我正在准备面试,我是 cakephp 的新手,在网上搜索时遇到了这个问题......
“当您使用 cakephp 运行应用程序时,第一个加载的文件是什么?”
回答:
面试官:当你使用cakephp运行应用程序时,第一个加载的文件是什么,
候选人:你能改变那个文件吗?
面试官:是的
bootstrap.php,是的,它可以通过 index.php 或通过 htaccess
进行更改
如果特定文件不可更改,则首先加载哪个文件。
我试图找出答案,但找不到。
有人可以帮我解决这个问题吗?
最佳答案
加载的第一个文件是 webroot 文件夹中的 index.php
(根据 .htaccess
重写规则),它将在包含路径中添加 CakePHP 的核心
CakePHP 1.3
if (!defined('CORE_PATH')) {
if (function_exists('ini_set') && ini_set('include_path', CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . ROOT . DS . APP_DIR . DS . PATH_SEPARATOR . ini_get('include_path'))) {
define('APP_PATH', null);
define('CORE_PATH', null);
} else {
define('APP_PATH', ROOT . DS . APP_DIR . DS);
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
}
}
if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) {
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);
}
CakePHP 2.1
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
if (function_exists('ini_set')) {
ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'));
}
if (!include('Cake' . DS . 'bootstrap.php')) {
$failed = true;
}
} else {
if (!include(CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php')) {
$failed = true;
}
}
然后在这两种情况下都包含 bootstrap.php
。
所以答案是:index.php
并且您不得修改它(除非您在某些 particular cases 中),然后 app/Config/bootstrap.php
和你 may modify it .
关于cakephp - 在 cakephp 中加载的第一个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10611135/