Yii Framework Forum: mudule and view layout - Yii Framework Forum

Jump to content

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

mudule and view layout Rate Topic: -----

#1 User is offline   genady 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 04-July 10

Posted 05 July 2010 - 08:54 PM

Hello,

I am new to framework (only a few days of playing around). I got a bot confused how layouts work. I hope you
guys can help me out.

I have my main site setup and under it I created a module I added following to config file:

'modules'=>array(
'adminTest'=>array('layout'=>'admin')
),

Under modules/adminTest/views/layouts I created a modified copy of the main.php of the main site layout.

in index.php under module I added following code:

<p>
Layout Path <?php echo $this->module->layoutPath ?> <br/>
Layout <?php echo $this->module->layout ?>
</p>

the output looks like:

Layout Path {removed}/protected/modules/adminTest/views/layouts
Layout admin


but the page still uses main.php layout form main site. What am I missing?

I am using code from svn 1.1.3-dev

thanks in advance for any idea you can give me. I feel like I am stuck. I want to keep module related
layout within that module
0

#2 User is offline   richie 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 41
  • Joined: 18-June 10

Posted 05 July 2010 - 09:22 PM

$this->layout = "admin";

$this->render('index');

try in your action!
0

#3 User is offline   genady 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 04-July 10

Posted 05 July 2010 - 10:28 PM

that did worked! Do I have to init this in each action for each comptroller? How come the global property
did not work? Does controller have a init routine that executed before each action that I can use?
0

#4 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 06 July 2010 - 08:39 AM

Yes of corse you can.

Instead of writing
$this->layout = "admin";
in the action you can use
public $layout='admin';
at top of your class.

If all your controllers in a module have to share some properies, you can set them in AdminTestModule::beforeControllerAction
0

#5 User is offline   genady 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 04-July 10

Posted 06 July 2010 - 09:25 AM

but why the module property does not get propagated to the controller level? According to doc it should.

Also if action 'a' will have 'public $layout= 'admin'' and I am actually activating action b then my init
will never gets hit?
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