Calling a controller/action directly from a view

Hi there,

I have been migrating my CMS from CakePHP to Yii for the last few months, and I am enjoying the great flexibility and clarity of this framework.

One thing I am not able to achieve with Yii is what cakePHP calls requestAction: a call to a specific controller/action[/params] from within a view, which retrieves a complete view (without a layout), that can be placed anywhere within the calling view.

For example, I have a model/controller/view for my menu items. I want to call e.g. "contoller:MenuItemController, action:index, id:1" to show a menu tree with ID 1. And I want to place the resulting view e.g. within the header of my main layout.

The best I could do so far was to create a partial view, which calls a component with a function which calls the MenuItem model to retrieve the menu tree data. The partial view then arranges the data in a desired layout.

I don’t know if this is the best practice to use. But CakePHP’s approach seems more intuitive and simple, and I wonder if there is a similar (or better) way to do this.

thanks

gm

CWidget was designed to solve this problem. Extend this class, put the model logic in its run() method, and create a view that displays the menu, then you can call it from any view (or layout) script.

Thanks, I will try that!

is there any other solution except Cwidget?

maybe http://www.yiiframework.com/doc/api/1.1/CController#forward-detail ?