Cakephp如何检查其命名约定和文件夹名称?

时间:2014-01-10 17:47:58

标签: php cakephp routing conventions

cakephp命名约定(即控制器名称应为CakesController.php,即以Controller结尾)和文件夹约定(即控制器文件来自app / Controller文件夹)定义在哪里即cakephp如何检查它。在哪个文件中定义。

1 个答案:

答案 0 :(得分:3)

大部分内容都是在Dispatcher的{​​{3}}和Router的帮助下发生的,例如:

protected function _loadController($request) {
    $pluginName = $pluginPath = $controller = null;
    if (!empty($request->params['plugin'])) {
        $pluginName = $controller = Inflector::camelize($request->params['plugin']);
        $pluginPath = $pluginName . '.';
    }
    if (!empty($request->params['controller'])) {
        $controller = Inflector::camelize($request->params['controller']);
    }
    if ($pluginPath . $controller) {
        $class = $controller . 'Controller';
        App::uses('AppController', 'Controller');
        App::uses($pluginName . 'AppController', $pluginPath . 'Controller');
        App::uses($class, $pluginPath . 'Controller');
        if (class_exists($class)) {
            return $class;
        }
    }
    return false;
}

来源:Inflector

另见https://github.com/cakephp/cakephp/blob/master/lib/Cake/Routing/Dispatcher.php#L244

typical CakePHP Request Lifecycle