CAKEPHP - 将默认路径更改为 webroot

2021-12-21 00:00:00 installation php cakephp

我是 cakephp 的新手,我在设置本地开发服务器时遇到了一些问题.我的蛋糕安装位于 http://localhost/dropbox/my_site/.但是,当我尝试访问该 url 时,它告诉我未设置 Dropbox 控制器.我如何告诉 CakePHP 从 my_site 而不是 /localhost/ 开始?

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/?

我已经尝试将 connect(/localhost/dropbox/*) 添加到路由中,但它似乎仍然在错误的位置寻找模型.

I've tried adding connect(/localhost/dropbox/*) to the routes, but it seems like it still looks for models in the wrong location.

我尝试在 app/webroot 中编辑 index.php,但所有示例都显示了如何以 linux 格式而不是 windows 格式编写目录,所以我不确定如何构建ROOT"

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'

推荐答案

CakePHP 将在子目录中愉快地工作 - 我有几个 Cake 站点在 上运行http://localhost/{appname} 在我的开发机器上.

CakePHP will work happily in a subdirectory - I have several Cake sites running at http://localhost/{appname} on my dev machine.

Cake 在根 index.php 文件中定义了它的 ROOT 目录.如果你往里面看,你会看到以下几行:

Cake defines its ROOT directory in the root index.php file. If you look inside you'll see the following lines:

define('ROOT', dirname(__FILE__));
define('WEBROOT_DIR', 'webroot');
define('WWW_ROOT', ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS);

因为它从 dirname(__FILE__) 获取 ROOT,所以它总是指向那个文件的位置.

Since it's taking ROOT from dirname(__FILE__), it will always point to that file's location.

我怀疑您的路由文件有问题.您是否创建了任何自定义路由规则来说明位于子目录中?如果你这样做了,你的蛋糕安装可能会尝试访问 http://localhost/dropbox/my_site/dropbox/a>... 这就是为什么您会收到该错误.

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.

相关文章