php CAKEPHP - 将默认路径更改为 webroot
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9485994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CAKEPHP - Change default path to webroot
提问by Stewie
I'm new to cakephp and I'm having some problems with setting up a local development server. I have my cake install located at http://localhost/dropbox/my_site/. However, when I try to visit that url, it tells me the dropbox controller isn't set up. How do I tell CakePHP to start in my_site
rather than /localhost/
?
我是 cakephp 的新手,我在设置本地开发服务器时遇到了一些问题。我的蛋糕安装位于http://localhost/dropbox/my_site/。但是,当我尝试访问该 url 时,它告诉我未设置 Dropbox 控制器。我如何告诉 CakePHP 开始my_site
而不是/localhost/
?
I've tried adding connect(/localhost/dropbox/*)
to the routes, but it seems like it still looks for models in the wrong location.
我已经尝试添加connect(/localhost/dropbox/*)
到路线,但它似乎仍然在错误的位置寻找模型。
I tried editing index.php in app/webroot but all the examples show how to write the directory in linux format rather than windows, so I'm not sure how to structure 'ROOT'
我尝试在 app/webroot 中编辑 index.php,但所有示例都显示了如何以 linux 格式而不是 windows 格式编写目录,所以我不确定如何构建“ROOT”
回答by Farray
CakePHP will work happily in a subdirectory - I have several Cake sites running at http://localhost/{appname} on my dev machine.
CakePHP 将在一个子目录中愉快地工作 - 我有几个 Cake 站点在我的开发机器上运行在http://localhost/{appname} 上。
Cake defines its ROOT directory in the root index.php file. If you look inside you'll see the following lines:
Cake 在根 index.php 文件中定义了它的 ROOT 目录。如果你看里面,你会看到以下几行:
define('ROOT', dirname(__FILE__));
define('WEBROOT_DIR', 'webroot');
define('WWW_ROOT', ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS);
Since it's taking ROOT from dirname(__FILE__)
, it will always point to that file's location.
由于它从 中获取 ROOT dirname(__FILE__)
,因此它将始终指向该文件的位置。
I suspect you have problems in your routing file. Did you create any custom routing rules to account for being located in a subdirectory? If you did, your cake install may be trying to access http://localhost/dropbox/my_site/dropbox/... and that's why you're getting that error.
我怀疑你的路由文件有问题。您是否创建了任何自定义路由规则来说明位于子目录中?如果您这样做了,您的 cake install 可能会尝试访问http://localhost/dropbox/my_site/dropbox/... 这就是您收到该错误的原因。
回答by Jason McCreary
This likely doesn't have so much to do with CakePHP as it does with your web server.
这可能与 CakePHP 没有太大关系,因为它与您的 Web 服务器有关。
If dropboxis your document root, it should be mapped accordingly in your web server configuration. For example using DocumentRoot
in Apache.
如果dropbox是您的文档根目录,则应在您的 Web 服务器配置中对其进行相应映射。例如DocumentRoot
在 Apache 中使用。