Yii Framework Forum: How to display the different - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to display the different Rate Topic: ***** 1 Votes

#1 User is offline   zbq 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 27-May 10

Posted 14 June 2010 - 04:18 AM

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.)

This post has been edited by zbq: 14 June 2010 - 04:42 AM

0

#2 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 15 June 2010 - 07:20 AM

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.
0

#3 User is offline   zbq 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 27-May 10

Posted 17 June 2010 - 03:30 AM

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.
0

#4 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 17 June 2010 - 06:12 AM

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
0

#5 User is offline   zbq 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 27-May 10

Posted 18 June 2010 - 02:31 AM

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?

This post has been edited by zbq: 18 June 2010 - 04:48 AM

0

#6 User is offline   zbq 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 27-May 10

Posted 18 June 2010 - 05:01 AM

I think I have figure it out :)
Thank you!
0

#7 User is offline   ISY Good 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 07-June 10

Posted 06 July 2010 - 01:24 PM

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!
0

#8 User is offline   zbq 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 27-May 10

Posted 09 July 2010 - 01:07 AM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users