How to display the different

E.g. I’m in /user/index, and in this view “index”, I want to invoke a function which is defined in “post” controller, what can I do? Or how can I invoke a controller (not the CURRENT controller) in a view

(PS: I’m sorry I submitted this post for a mistake with the uncompleted title, but I did not find where to change it.)

Is a bit strange that in a controller you need a function of another one controller.

Maybe this function should be in a model: if you are using the same model il both controllers you can put the function in the model (expecially if the function works with the data of the model itself).

If is not depending from the model, is better to create a Component for this function.

Anyway you can always instantiate a controller


$cont=new CController('site');

But is a bit strange operation.

Hi zaccaria,

In my site, there are two links “A” and “B”, they are referred to two controllers (/index.php/a and /index.php/B). But both of them are the tabs of a tabview UI, when click the link (either link), it will take visitor to a view (e.g. mainpanle_tpl.php), in this view page, I use following codes to invoke the CTabView UI:



if(isset($dataProvider)){


    $viewData['dataProvider']=$dataProvider;


}





if(isset($model)){


    $viewData['model']=$model;


}





//current tab content


$Tabs = array(


    'tab1'=>array('title'=>'A', 'view'=>'/a/index'),


    'tab2'=>array('title'=>'B', 'view'=>'/b/index'),


);





$this->widget('CTabView', array('tabs'=>$Tabs, 'viewData'=>$viewData, 'activeTab'=>'tab2'));

My purpose is to use different data in both tabs, but if use the codes above, the “$dataProvider” will be incorrect. When the tabview is shown up, it does not use the data in model B, instead, it uses the mode A’s data in /b/index.

To resolve the problem, I want to re-build both of the Model A and Model B’s data in the view page. And the re-build functions are defined in Controller A and Controller B. So I want to use Controller A’s function in B’s View and use Controller B’s function in A’s View.

That’s why I have this strange idea.

You can use 2 subview for the tab, and those subview will be rednered with the ‘viewData’. Create 2 files _a.php and _b.php for the subView.

You can pass the data you need in this view with the property ‘data’.

Is not needed more than one controller, better to do all in one file

Yes, I want to combine them into one controller ever, but actually A are not connected with B really in logic.

Yesterday, I found another UI called "CJuiTabs":



$this->widget('zii.widgets.jui.CJuiTabs', array(


    'tabs'=>array(


        'StaticTab 1'=>'Content for tab 1',


        'StaticTab 2'=>array('content'=>'Content for tab 2', 'id'=>'tab2'),


        // panel 3 contains the content rendered by a partial view


        'AjaxTab'=>array('ajax'=>array('/a/index')),


    ),


    // additional javascript options for the tabs plugin


    'options'=>array(


        'collapsible'=>true,


    ),


));

But in this UI, how can I set the active tab or the UI tab? And how to make all the links and the form submittion to point to current tab? Maybe I should say how to make them work as AJAX in the current tab?

I think I have figure it out :)

Thank you!

zbq, how did you figure it out? could you post an example of what you concluded? In the spirit of community, your answer may help others learn more.

Thanks!

I used "CJuiTabs" instead of "CTabView", and you can check the extra parameters in Jquery UI section. Actually "CJuiTabs" extended Jquery Tabs UI by Yii, so you can also use the Jquery options in Yii CJuiTabs.

zbq can you show us how you did it?? please? i’ve been working for this in 6 days straight.