开发者

CakePHP 404 page is not using layout set in AppController

I have 2 versions of my site, (depending on what domain was used to access it). Each version is a completely different brand.

In my AppController I have some开发者_运维百科thing like this:

// use default layout for posh site
// use cheap layout for cheap site
function beforeFilter() 
{
    parent::beforeFilter(); 

    if(isCheap())
    {
        $this->layout = 'cheap';
    }      
} 

So now, when someone goes to my site via posh.com they get the posh layout, if someone goes to my site via cheap.com they get the cheap layout.

However, if someone hits the 404 page on the cheap site, it does not load the cheap layout, it loads the default layout. So from their perspective, suddenly they will appear to be in a different site.

How can I fix this?


This seems work, I had to duplicate the logic though, which I do not like.

I created the file app/error.php containing:

class AppError extends ErrorHandler 
{ 
    function error404($params) 
    { 
        if(isCheap())
        {
            $this->controller->layout = "cheap";
        } 
        parent::error404($params); 
    } 
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜