English 中文(简体)
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/





相关问题
PHP Framework: Ebay Like Site

I am going to be builiding a site like ebay - with all the features of ebay. Please note my payment method is limited to paypal. What would be the best PHP framework to use to build this quickly, ...

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

Using DISTINCT in a CakePHP find function

I am writing a CakePHP 1.2 app. I have a list of people that I want the user to be able to filter on different fields. For each filterable field, I have a drop down list. Choose the filter ...

Assistance with CakePHP model relationships

How would I represent the following in a CakePHP model? Product ======= product_id .... Cart ==== cart_id .... Carts_Products ============== cart_id product_id quantity

Prevent controller from trying to autoload model

I am a beginning Cake user and trying to do some work on an already existing application. Running into a problem when I create a new controller. I have created StoreController and when I try to call ...

热门标签