[solved] Nested Modules with same layout

Hi all,

currently I am doing a project, with nested modules like this:




ROOT

    - modules

             - admin

                    - modules

                             - catalog



I use two different layouts in ROOT and admin, and catalog will use the layouts in admin/views/layouts/.

but I can’t manage to get the correct rendering when I am viewing /admin/catalog, how can I fix it?

hey!

you will need to setup the layoutPath property of the module

try the following code in your catalog module entry script

/yourwebapp/modules/admin/modules/catalog/Catalog.php:




	public function beforeControllerAction($controller, $action)

	{

		if(parent::beforeControllerAction($controller, $action))

		{

		    // this method is called before any module controller action is performed

		    // you may place customized code here

			$layoutPath= Yii::getPathOfAlias('application.modules.admin.views.layouts');

			$this->setLayoutPath($layoutPath);

				

			//$viewPath=...path to views if needed...;

			//$this->setViewPath($viewPath);


			return true;

		}

		else

			return false;

	}



not tested, dump the getPathOfAlias to see if it is the correct path you want

hope it helps

regards

:)

I have added them in CatalogModule but that doesn’t work.

In fact, the value of layoutPath is correct.

Is there any solutions on this, I can’t find it work correctly.

Note that I am using Yii 1.1.7

Thanks!

Do anyone have ideas?

Lastly, I figure out the solution of this problem.

In fact it is the path problem in the layout files in /protected/modules/admin/view/layouts.

The overall structure is this:




ROOT

    - modules

             - admin

                    - modules

                             - catalog



CatalogModule.php





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

	parent::init();

	

	$this->setImport(array(

		'catalog.models.*',

		'catalog.components.*',

	));

		

	// Add this two line to override the layoutPath

	$layoutPath= Yii::getPathOfAlias('application.modules.admin.views.layouts');

	$this->setLayoutPath($layoutPath);

}




And the column1 layout under /protected/modules/admin/view/layouts

The parameter in $this->beginContent() should be using Path Alias:

application.modules.admin.views.layouts.main




<?php $this->beginContent('application.modules.admin.views.layouts.main'); ?>

<div class="container">

	<div id="content">

		<?php echo $content; ?>

	</div><!-- content -->

</div>

<?php $this->endContent(); ?>



Cheers :rolleyes:

Hi Dear Joshua Tam

like your project i have this structure

root -> modules -> admin -> modules -> auth

i want to use layout of admin in auth.

how i can do it?

Hi,

Basically, you have to add those code in your AuthModule.php and you have to edit the layouts placed in /protected/modules/admin/views/layouts/

AuthModule.php




public function init() {


        //Your Own Code Here...


        // Add this two line to override the layoutPath

        $layoutPath= Yii::getPathOfAlias('application.modules.admin.views.layouts');

        $this->setLayoutPath($layoutPath);

}



column1.php (for example), change //layouts/main to application.modules.admin.views.layouts.main




<?php $this->beginContent('application.modules.admin.views.layouts.main'); ?>

<div class="container">

        <div id="content">

                <?php echo $content; ?>

        </div><!-- content -->

</div>

<?php $this->endContent(); ?>



Hope this help!