在CakePHP中更改管理布局 [英] Change admin layout in CakePHP

查看:93
本文介绍了在CakePHP中更改管理布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在cakephp工作,我的/app/config/routes.php文件中有以下两行:

I am working in cakephp, and I have the following two lines in my /app/config/routes.php file:

/**
 * ...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

I also have a layout at /app/views/layouts/admin.ctp

但是,当我访问管理网址时,布局不会更改

However, the layout is not changed when I visit admin URLs

推荐答案

code> app / app_controller.php 并将其放在:

Create a app/app_controller.php and put this in:

<?php
class AppController extends Controller {

    function beforeFilter() {
        if (isset($this->params['prefix']) && $this->params['prefix'] == 'admin') {
            $this->layout = 'admin';
        } 
    }

}



<如果您在其他控制器中使用它,则忘记调用 parent :: beforeFilter();

Semi与问题相关,你不需要定义路由,你只需要启用 Routing.admin config选项并将其设置为 admin app / config / core.php 中。 (CakePHP 1.2)

Semi related to the question, you don't need the routes defined, you just need to enable Routing.admin config option and set it to admin in the app/config/core.php. (CakePHP 1.2)

这篇关于在CakePHP中更改管理布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆