首页 文章

cakephp改变了不同用户的布局

提问于
浏览
0

我是cakephp的新手,不过我到处寻找答案,特别是食谱 .

我正在尝试从cakebook的教程中制作我的"tutorial blog"的前端和后端 . 我在( /View/Layouts )中创建了名为 admin.ctpauthor.ctpdefault.ctp 的不同布局,并且在控制器中有一些代码我可以打赌它会起作用,但不行 .

public function beforeFilter() {
    parent::beforeFilter();

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

}

它总是选择最后一个default.ctp,我不知道为什么

1 回答

  • 0

    (在问题编辑中回答 . 转换为社区维基答案 . 请参阅Question with no answers, but issue solved in the comments (or extended in chat)

    OP写道:

    转而我没有在我的core.php中设置任何前缀,我试图设置它们但没有任何进展,如果有人可以帮我根据我的代码设置一些前缀我将不胜感激 . 不过我解决了编辑控制器的问题,它工作正常 . 它不专业,我知道,但现在它应该对我有用 .

    <?php
    
    class ProductsController extends AppController
    {
    public $helpers= array('Html','Form','Session');
    public  $components = array('Session');
    
    
    public  function index()
    {
        if($this->Session->read('Auth.User.role') == 'admin')
        {
            $this->layout = 'admin';
        }
        else if($this->Session->read('Auth.User.role') == 'author')
        {
            $this->layout = 'author';
        }
        else
        {
            $this->layout = 'default';
        }
        $this->set('item',  $this->Product->find('all'));
    }?>
    

相关问题