I am new to YII. How to call an action from another action of the same controller. Suppose I am in action A. I need to call action B with two parameters. My controller name is Master Controller. How will I perform this. Please say me a solution. Thanks in advance.
My controller:
class NimsoftController extends Controller
{
    public function actionStore_action($action,$data_id)
    {
          $model= new NimsoftUserLoginAction;
          $model->user_id=Yii::app()->user->id;
          $model->action=$action;//"Deleted";
          $model->affected_data_id=$data_id;//"22";
          $model->save();
    }
    public function actionSearch($id)
    {
        $cust_id = $id;
        $criteria = new CDbCriteria();
        $criteria->condition = "host_customer_id = '$cust_id'";
        $details = NimsoftHost::model()->find($criteria);
        $criteria2 = new CDbCriteria();
        $criteria2->condition = "cust_id= '$details->host_customer_id'";
        $name = MasterCustomers::model()->find($criteria2);
        $dataProvider = new CActiveDataProvider('NimsoftHost', array(
            'criteria' => $criteria,
            'pagination'=>array('pageSize'=>40)
        ));
        $model = new NimsoftHost();
        $this->actionStore_action(array('action'=>'search', 'data_id'=>$cust_id));
        $this->render('index',array(
            'dataProvider' => $dataProvider,
            'details' => $details,
            'name' => $name->cust_name,
            'model' => $model
        ));
    }
}
                You can simply call the function directly, or,
$this->actionMyCustomAction(); exit;
you can perform a redirect to the action:
$this->redirect('anotherControllerName/myCustomAction');
or this if you are in the same controller:
$this->redirect('myCustomAction');
UPDATE:
You are passing the variables wrongly:
$this->actionStore_action(array('action'=>'search', 'data_id'=>$cust_id));
It should be two separate variables:
$this->actionStore_action('search', $cust_id);
This has NOTHING to do with Yii. It's only basic function calling.
$this->forward('site/contact');
In case of forward your URL will not be change and you cannot send extra parameter in this.
If you want to send extra parameter then use redirect.
   $this->redirect(Yii::app()->createUrl('site/contact', array('id' => '22')));
Hope this will help you..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With