Yii Framework Forum: Using a module-specific layout file - Yii Framework Forum

Jump to content

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

Using a module-specific layout file Rate Topic: -----

#1 User is offline   Sander 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 03-November 09
  • Location:Amsterdam, Netherlands

Posted 03 November 2009 - 10:06 AM

I just created an admin module for my app and I'd like to use a specific layout file to render it in.

I changed the layoutPath property in the init() function of protected/modules/admin/AdminModule.php and created a file main.php in protected/modules/admin/views/layouts with my alternate layout. However, when I go to index.php?r=admin, the content is still rendered in the global app layout.

What more do I need to do to make this happen?
0

#2 User is offline   got 2 doodle 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 248
  • Joined: 12-December 08
  • Location:Beautiful Nova Scotia, Canada

Posted 03 November 2009 - 10:41 AM

View PostSander, on 03 November 2009 - 10:06 AM, said:

I just created an admin module for my app and I'd like to use a specific layout file to render it in.

I changed the layoutPath property in the init() function of protected/modules/admin/AdminModule.php and created a file main.php in protected/modules/admin/views/layouts with my alternate layout. However, when I go to index.php?r=admin, the content is still rendered in the global app layout.

What more do I need to do to make this happen?

Hi, I am learning Yii also and I am setting up admin and frontend layouts.

I followed this cookbook article in particular
this comment was very valuable.

I setup a frontend and backend controller and all of my controllers are extensions of these controllers.

In my case I wanted to be able to choose from various layouts (admin chooses) so that the look of the frontend can be easily changed by the admin. I store the name of the layout in a database and retrieve it in the front end controller along with a css file (again chosen by the admin).
<?php

class FrontendController extends CController
{

public function init(){
        parent::init();
//        Get the layout
        $this->layout = sitekeys::model()->find('sitekey=:sitekey',array(':sitekey'=>'layout'))->value;
//        Get the CSS
        $style = sitekeys::model()->find('sitekey=:sitekey',array(':sitekey'=>'stylesheet'))->value;
        
		// this registers a bunch of css files, the render command adds them to the web doc
        $CssFiles = array('reset','text','960',$style);
        foreach($CssFiles as $Css){
               Yii::app()->clientScript->registerCssFile('/css/'.$Css.'.css', '');
        }
        
    }
}


I know this doesn't exactly answer your question but I hope it helps.

doodle ;)
Check out myYii powered website
0

#3 User is offline   jayrulez 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 348
  • Joined: 29-July 09

Posted 03 November 2009 - 02:38 PM

View PostSander, on 03 November 2009 - 10:06 AM, said:

I just created an admin module for my app and I'd like to use a specific layout file to render it in.

I changed the layoutPath property in the init() function of protected/modules/admin/AdminModule.php and created a file main.php in protected/modules/admin/views/layouts with my alternate layout. However, when I go to index.php?r=admin, the content is still rendered in the global app layout.

What more do I need to do to make this happen?



you do not need to change the layout path. if you just create the main.php layout file for the module then it will use it automatically.
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";

python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]

ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}


You say Tomato, I say Tomato.
0

#4 User is offline   Sander 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 03-November 09
  • Location:Amsterdam, Netherlands

Posted 03 November 2009 - 05:29 PM

View Postjayrulez, on 03 November 2009 - 02:38 PM, said:

you do not need to change the layout path. if you just create the main.php layout file for the module then it will use it automatically.

Well, no. I tried that first, but it didn't work.
0

#5 User is offline   got 2 doodle 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 248
  • Joined: 12-December 08
  • Location:Beautiful Nova Scotia, Canada

Posted 03 November 2009 - 05:38 PM

View PostSander, on 03 November 2009 - 05:29 PM, said:

Well, no. I tried that first, but it didn't work.

I have yet to touch on modules but have you tried the viewPath attribute?

doodle
Check out myYii powered website
0

#6 User is offline   jayrulez 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 348
  • Joined: 29-July 09

Posted 03 November 2009 - 08:27 PM

View PostSander, on 03 November 2009 - 05:29 PM, said:

Well, no. I tried that first, but it didn't work.



Ahh, i see, that used to work. Must have changed at some point, anyway, i just tested this method and it should work just fine. Specify your layout file when you configure your modules in protected/config/main.php like this
	'modules'=>array(
		'accounts'=>array(
			'layout'=>'main',
		),
	),


it will search for main.php layout file under protected/modules/accounts/views/layouts
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";

python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]

ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}


You say Tomato, I say Tomato.
1

#7 User is offline   Sander 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 03-November 09
  • Location:Amsterdam, Netherlands

Posted 04 November 2009 - 03:06 AM

View Postjayrulez, on 03 November 2009 - 08:27 PM, said:

Ahh, i see, that used to work. Must have changed at some point, anyway, i just tested this method and it should work just fine. Specify your layout file when you configure your modules in protected/config/main.php like this
	'modules'=>array(
		'accounts'=>array(
			'layout'=>'main',
		),
	),


it will search for main.php layout file under protected/modules/accounts/views/layouts

Thank you, that fixed it.
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