开发者

Themes in CakePHP 2.0.0-dev

Trying to set up a mobile theme in CakePHP 2.0.0-dev, but it isn't working as it did in 1.3. Have there been any changes to the themes implementation in 2.0?

Structure as follows:

app/views/themed/mobile/layouts/default.ctp
app/views/themed/mobile/pages/home.ctp

Then in app/app_controller.php:

public function beforeRender()
{
    if ($this->RequestHandler开发者_高级运维->isMobile()) {
        $this->view = 'Theme';
        $this->theme = 'mobile';
    }
}

Hit the home page... But no mobile site... Just the normal site. No errors, nothing in debug or error logs. No errors, no exceptions. Nothing. As if themes have been deprecated or something.

Any ideas anyone?


try:

$this->layout='mobile';

That should then display the layout when browsed to by a mobile device.


Solved!

After looking in cake/libs/view/theme.php, I read this:

...You can set $this->theme and $this->viewClass = 'Theme'...

public function beforeRender()
{
    if ($this->RequestHandler->isMobile()) {
        $this->viewClass = 'Theme';
        $this->theme = 'mobile';
    }
}

So, looks like a slight change in version 2.0 to the variable name from $this->view to $this->viewClass.

Works now!


If anyone has further issues with this, I have a post with some more information at http://blog.ergatides.com/web-design/themes-in-cakephp-2-0-0/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜