1

尝试在 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';
    }
}

点击主页...但没有移动网站...只是普通网站。没有错误,调试或错误日志中没有任何内容。没有错误,没有例外。没有什么。好像主题已被弃用或其他什么。

有什么想法吗?

4

3 回答 3

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 略有变化。

现在工作!

于 2011-05-17T11:35:04.540 回答
1

尝试:

$this->layout='mobile';

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

于 2011-05-15T13:42:07.607 回答
0

如果有人对此有进一步的问题,我会在http://blog.ergatides.com/web-design/themes-in-cakephp-2-0-0/上发布更多信息

于 2011-05-23T11:18:15.707 回答