Robert Love
Robert Love

Reputation: 141

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?

Upvotes: 1

Views: 2229

Answers (3)

user716580
user716580

Reputation:

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/

Upvotes: 0

Robert Love
Robert Love

Reputation: 141

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!

Upvotes: 1

Gevious
Gevious

Reputation: 3252

try:

$this->layout='mobile';

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

Upvotes: 1

Related Questions