Subaction in action?

I have a section on my website where people can edit their Company information (index.php?r=company/update&id=42). People can also add, edit or delete extra information (as much as they want, it’s a single line of text). This extra information is stored in a table called company_extra (with a model called CompanyExtra). Now i want the CRUD actions to be available for this extra information (which is related to the company).

So i need some sort of subactions. I have done this in my Company Controller like this, so i can call index.php?r=company/extra&id=42&sa=update&eId=43:


public function actionExtra($id, $sa=null, $eId=null)


        $model = $this->loadModel($id);

        if ($model->userId !== Yii::app()->user->getId()) {

            throw new CHttpException(403, 'Je hebt geen toegang tot deze actie');


        switch($sa) {

            // Create new extra info

            case 'create':

              $eModel=new CompanyExtra;

              // Uncomment the following line if AJAX validation is needed















            // Update extra info

            case 'update':

            // Update part here


            // Manage extra info


              $dataProvider=new CActiveDataProvider('CompanyExtra', array(








              $this->render('extra', array(

                  'dataProvider' => $dataProvider,

                  'model' => $model,







Is this a good way to do this? Or are there better alternatives?

I would create separate crud actions for companyExtra in your companyController. addExtraAction, removeExtraAction, updateExtraAction sound ok for me :). IMO actions should result in setting flash message and redirecting back to profile view, instead of rendering views by themselves. That will limit users confusion as they will see the same address all the time.

Yeah, that sounds as a good idea indeed!