Page 1 of 1
Using a module-specific layout file
#1
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?
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?
#2
Posted 03 November 2009 - 10:41 AM
Sander, 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?
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
#3
Posted 03 November 2009 - 02:38 PM
Sander, 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?
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.
#5
Posted 03 November 2009 - 05:38 PM
Sander, 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
#6
Posted 03 November 2009 - 08:27 PM
Sander, 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.
#7
Posted 04 November 2009 - 03:06 AM
jayrulez, 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
it will search for main.php layout file under protected/modules/accounts/views/layouts
'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.
Share this topic:
Page 1 of 1

Help














