你可以告诉 cake 你想从哪个文件夹路径调用你的视图。
把它放在你的引导 App::build(array('View' => array( $my_lib_folder_path.DS )));
这是我构建的一个片段,让 cake 搜索我的视图文件夹中的所有文件夹。因为我喜欢将我的代码安排在文件夹中。即查看/CompanyManagement/AddCompanies/index.ctp 查看/CompanyManagement/EditCompanies/index.ctp 查看/CompanyManagement/DeleteCompanies/disable.ctp 查看/CompanyManagement/DeleteCompanies/delete.ctp
我的代码告诉 cake 搜索我的视图文件夹下的所有文件,并查看子文件夹以找到我想要的特定视图。但从搜索中排除布局、元素和助手文件夹。
应用程序/配置/bootstrap.php
define('ELEMENTS', APP.'View'.DS.'Elements');
define('HELPERS', APP.'View'.DS.'Helper');
define('LAYOUTS', APP.'View'.DS.'Layouts');
define('VIEWS', APP.'View'.DS)
includeViews();
function includeViews() {
App::uses('Folder', 'Utility');
$folder = new Folder(VIEWS);
$folders_paths = current($folder->read($sort = true, $exceptions = false, $fullPath = true));
foreach( $folders_paths as $folder_path ) {
$isAHelperPath = (new Folder($folder_path))->inPath(HELPERS);
$isALayoutPath = (new Folder($folder_path))->inPath(LAYOUTS);
$isAnElementPath = (new Folder($folder_path))->inPath(ELEMENTS);
if ( ! $isAHelperPath && ! $isALayoutPath && ! $isAnElementPath ) {
App::build(array('View' => array( $folder_path.DS )));
}
}
}