ccampbell / sonic

fast, lightweight PHP 5.3 MVC framework
http://www.sonicframework.com
Apache License 2.0
63 stars 11 forks source link

Understanding layouts #17

Closed gordyr closed 12 years ago

gordyr commented 12 years ago

I am using the 'main' layout exactly as described in the tutorial on the Sonic website.

This is perfect for the bulk of my app as the 'main' layout itself contains the head/footer and bare skeleton.

The page itself is then built up of several views...

What I am failing to understand however is how I can have a completely separate layout for just one specific page.

Lets take the following example:

www.example.com uses layout 'layout1'

How can I make www.example.com/example2 a totally different layout named 'layout2' rather than 'layout1'. With layout2 having a completely different header/footer/skeleton etc.

My apologies... I am probably just not grasping something very simple here. Any help you could give me would be much appreciated.

I have tried using disableLayout and setLayout in the controller but without success.

ccampbell commented 12 years ago

I am guessing this is because you are using turbo mode. In turbo mode the controller methods do not run until after the view has been rendered.

This means you have to force a different layout somewhere else. I am not sure off the top of my head where this would happen. I have to dig through the code :P

You may be able to use __construct() in a controller to force a specific controller to a new layout in which case you can route everything through that controller:

class NewLayoutController extends Sonic\Controller
{
    public function __construct()
    {
        $this->setLayout('new');
    }
}

If this doesn't work then you may have to do something in your Delegate.php file to tell it that certain requests should use a different layout.

I believe it would happen in this method http://sonicframework.com/docs/1.1/App_Delegate/actionWasCalled

gordyr commented 12 years ago

Perfect! Using __construct() as suggested works fine.

Again many thanks :-)