How To Render A Module?

This looks pretty basic, but I checked online and all I could find is how to render a specific view INSIDE a module.

What I want to do is to render a module as a "widget" or to do a partialRender of the module.

I want to pass by the regular module controller and display the appropriate view.

Thank you for your time :lol:

Why you want to do that directly?

In the way you want is not right philosophy model/viewer/controller

The right way is to do that like widget

I have a specific need for that, anyone? :mellow:

You may could create an instance of your controller inside model and with custom method render your model like that

$mycontroller->partialRender(‘yourview’,array(

		'model'=>$this,


	));

But this approach is a little bit strange

Maybe I was not clear in my question. :)

I would like to use a "module as a widget". Meaning I would like anywhere in the site to be able to call a module

EX: $this->widget(‘components.modules.MyModule’);

EX: $this->partialRender(‘components.modules.MyModule’);

And the module will be rendered according to the logic of the module(controller), like an IFrame I guess; just a windows inside another site. :)

Ok now it is more clear to me!

You could use this

Yii::import(’'MyModule.models.yourmodel);

$this->widget(‘myModule.components.MyWidget’); //you should may change the alias path both import and widget

So, make a specific action to use above with accessRules permissions

I try to understand your logic here :)

Can you explain me what are you trying to call and for what reason?

And also could I use porlets in any way to display a module?

thanks. :D

Assuming that You have a module named ‘mymodule’

So your folder structure is

protected/modules/mymodule

protected/modules/mymodule/components/mywidget.php

protected/modules/mymodule/components/views/mywidget.php

mywidget.php has class mywidget extends CWidget.

Into this file you have to put init() and run() method

in the run method: $this->render(‘mywidget’);

In the views/mywidget.php put your desired code like a normal view

Thats it! now you can execute your module widget from anywhere

For example put the below code at the end of file protected/views/site/index.php

$this->beginWidget(‘zii.widgets.CPortlet’, array(‘title’=>‘My module widget’,));

$this->widget(‘mymodule.components.mywidget’);

$this->endWidget();

It is done! :)