我在 cakephp 工作,我的 /app/config/routes.php 文件中有以下两行:
/**
* ...and setup admin routing
*/
Router::connect('/admin/:controller/:action/*', array('action' => null, 'prefix' => 'admin', 'admin' => true, 'layout' => 'admin' ));
/**
* ...and set the admin default page
*/
Router::connect('/admin', array('controller' => 'profiles', 'action' => 'index', 'admin' => true, 'layout' => 'admin'));
我在 /app/views/layouts/admin.ctp 也有一个布局
但是,当我访问管理 URL 时,布局没有改变
创建一个app/app_controller.php
并将其放入:
<?php
class AppController extends Controller {
function beforeFilter() {
if (isset($this->params['prefix']) && $this->params['prefix'] == 'admin') {
$this->layout = 'admin';
}
}
}
别忘了打电话parent::beforeFilter();
如果您在其他控制器中使用它,则在您的控制器中。
与问题半相关,您不需要定义路由,只需启用Routing.admin
配置选项并将其设置为admin
in the app/config/core.php
。 (CakePHP 1.2)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)