CakePHP 2.0.0-dev中的主题

时间:2011-05-15 11:46:47

标签: cakephp themes cakephp-1.3 cakephp-2.0

尝试在CakePHP 2.0.0-dev中设置移动主题,但它不像1.3中那样工作。 2.0中的主题实现是否有任何变化?

结构如下:

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

然后在app / app_controller.php中:

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

点击主页...但没有移动网站......只是正常的网站。没有错误,没有调试或错误日志。没有错误,没有例外。没有。好像主题已被弃用或其他什么。

任何想法?

3 个答案:

答案 0 :(得分:1)

尝试:

$this->layout='mobile';

然后应该在移动设备浏览时显示布局。

答案 1 :(得分:1)

解决!

在查看cake / libs / view / theme.php后,我读到了这个:

  

...您可以设置$this->theme$this->viewClass = 'Theme' ...

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

因此,看起来版本2.0中的变量名称从 $ this-> view $ this-> viewClass 略有变化。

立即行动!

答案 2 :(得分:0)

如果有人对此有进一步的问题,我在http://blog.ergatides.com/web-design/themes-in-cakephp-2-0-0/

上发布了一些更多信息