Yii Framework Forum: Change module layout - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Change module layout Nothing seems to be working! Rate Topic: -----

#1 User is offline   Lilt 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 06-July 10

Posted 27 July 2010 - 07:05 AM

I created a module using Gii, called admin, which I want to use an entirely different layout to the rest of the site.

Now I can't seem to be able to change the default controller from anything but the 'protected/views/layouts/main.php' default. I've tried setting the $layout and $layoutPath properties in maybe 20 different ways, and still nothing works. I've tried changing it in my AdminModule.php class in both the init() function and declaring "public $layout = ". I've tried using Yii::app()->layout and Yii::app()->setLayoutPath() directly, I've tried setting it in the config file, and I've tried changing the layout in the controller using these methods above. Still, my site will load nothing other than the default 'main' view.

This is despite the fact that I'm still getting errors when I attempt to specify an invalid layout path, so it's obviously parsing my input but not using it.

I've searched the forums thoroughly and wasn't able to find a solution to this problem. Can someone throw me a bone? This is driving me nuts!
0

#2 User is offline   mbi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 614
  • Joined: 08-May 09

Posted 27 July 2010 - 07:15 AM

in your AdminModule.php you can change the layout

public function init()
{
    // import the module-level models and components
    $this->setImport(array(
        'administrator.models.*',
        'administrator.components.*',
    ));

    $this->layout = 'admin';
}


make sure your layoutFile 'admin.php' is located in modules/admin/views/layouts

at least this works with v1.0.12
1

#3 User is offline   Lilt 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 06-July 10

Posted 27 July 2010 - 07:30 AM

View Postmbi, on 27 July 2010 - 07:15 AM, said:

in your AdminModule.php you can change the layout

public function init()
{
    // import the module-level models and components
    $this->setImport(array(
        'administrator.models.*',
        'administrator.components.*',
    ));

    $this->layout = 'admin';
}


make sure your layoutFile 'admin.php' is located in modules/admin/views/layouts

at least this works with v1.0.12


Thanks for your reply, but this is my code:

    public function init()
    {
        // this method is called when the module is being created
        // you may place code here to customize the module or the application

        // import the module-level models and components
        $this->setImport(array(
            'admin.models.*',
            'admin.components.*',
        ));
		
        $this->layout = 'admin';

    }


It's still showing the protected/views/layouts/main.php layout, I do have an admin.php layout in modules/admin/views/layouts.

To clarify, I'm using yii-1.1.3.r2247
0

#4 User is offline   Sniper 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 55
  • Joined: 03-March 10
  • Location:Planet Ruby on Rails

Posted 27 July 2010 - 08:24 AM

have a look at http://www.yiiframew...dpost__p__51955

try removing $layout in Controller.php under components.
0

#5 User is offline   Lilt 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 06-July 10

Posted 27 July 2010 - 08:35 AM

View PostSniper, on 27 July 2010 - 08:24 AM, said:

have a look at http://www.yiiframew...dpost__p__51955

try removing $layout in Controller.php under components.

Thanks! That did the trick! :D I thought I was going crazy :(
0

#6 User is offline   Juan M. Escobar T. 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 07-April 13
  • Location:Colombia

Posted 11 April 2013 - 01:19 AM

A stupid point, but who knows. You need add first on top class:
public $layout;
. Then use:
$this->layout = '/layouts/YourLayoutName';

0

#7 User is offline   satyanarayana 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 30-January 14
  • Location:Hyderabad

Posted 05 February 2014 - 10:57 AM

View PostLilt, on 27 July 2010 - 08:35 AM, said:

Thanks! That did the trick! :D I thought I was going crazy :(


thanks, that worked for me.
could you please explain it why?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users