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.
In my site, there are two links “A” and “B”, they are referred to two controllers (/index.php/a and /index.php/. 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:
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.
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 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.