cakephp - 在 cakephp 中加载的第一个文件

标签 cakephp cakephp-1.3

我正在准备面试,我是 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/

相关文章:

php - CakePHP 中的变量前缀路由

php - 为什么要使用 CakePHP 的 HTML Helpers?

php - 从 cakephp 中的输入中删除多余的空格

file - CakePHP 复制文件到新目录

php - Cakephp 3 动态更改数据库连接?有效率吗?

cakephp 查找列表

mysql - CakePHP - 在关系 HABTM 中具有复合名称的表

Cakephp - 如何让错误页面有自己的布局?

mysql - phpmyadmin 正在将“保存”到 mysql 数据库而不是“从 cakephp

mysql - cakephp 1.3 模型中的交叉连接表