Yii Framework Forum: Add actions to a controller - Yii Framework Forum

Jump to content

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

Add actions to a controller add actions to controllerA that extends ControllerB Rate Topic: -----

#1 User is offline   zitter 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 14-July 09

Posted 18 April 2010 - 03:43 AM

Hi, I have controllerA that has:

public function actions(){
return array(
'act1' => 'application.controllers.Dir.Act1Action',
'act2' => 'application.controllers.Dir.Act2Action',
);
}


and then I have controllerB extends controllerA. I want to add some actions to controllerB, without loosing controllerA's actions.
If I do:
public function actions(){
return array(
'act3' => 'application.controllers.Dir.Act3Action',
'act4' => 'application.controllers.Dir.Act4Action',
);
}


Php returns: cannot redeclare controllerB::actions() in /path/to/controllerB. (sorry, my fault)
So, is there a way to inherit actions from parent controller and add other actions to controller child?

TIA
Danilo
0

#2 User is offline   zitter 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 14-July 09

Posted 18 April 2010 - 03:53 AM

OK, maybe I can solve adding public function actionAct3(){} to add other function. Anyway I would like to know if it is possibile to add actions in the way I've explained in first post :)
0

#3 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 18 April 2010 - 03:54 AM

I guess you simply have to merge the 2 arrays. try:

public function actions()
{
   return CMap::mergeArray(parent::actions(), array(
      'act3' => 'application.controllers.Dir.Act3Action',
      'act4' => 'application.controllers.Dir.Act4Action',
   ));
}

1

#4 User is offline   zitter 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 14-July 09

Posted 18 April 2010 - 03:57 AM

Y!!++
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