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