CakePHP 2.0.0-dev 中的主题

发布于 2024-11-07 07:58:36 字数 519 浏览 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';
    }
}

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

有人有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

新雨望断虹 2024-11-14 07:58:36

try:

$this->layout='mobile';

当移动设备浏览时,应该会显示布局。

try:

$this->layout='mobile';

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

︶葆Ⅱㄣ 2024-11-14 07:58:36

解决了!

查看 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

现在可以工作了!

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!

谜泪 2024-11-14 07:58:36

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

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文