Call a controller action(function) into another controller action(function) in Yii

Suppose a situation when you need to call a controller action(function) into another controller action (function) in Yii framework .So you just need to follow the below code


For Example : Suppose you have two controller

(1)- UserController
(2)- AdminController

In UserController there are alots of function like Below

(1)- UserController
                 (a)- actionLogin()
                 (b)- actionRegister()
                 (c)- actionCheckLogin()
                 (d)-  ------

(2)- AdminController
                 (a)- actionActivity()
                 (b)- actionUserDetail()
                 (c)-  ------
                 (d)-  ------
 
Now i want to call CheckLogin action into UserDetail action.To fulfill this requirement i just write down below code.

x---------------------x---------------------------x-----------------------x

function actionUserDetail(){

 Yii::import('application.controllers.UserController');  // Here first you have to import that controller

 $check = UserController::CheckLogin ();  // Than call your action

}

x---------------------x---------------------------x-----------------------x

Don't forgot to leave a comment .If you like it .
             
Happy coding guys :)                  

Post a Comment

Previous Post Next Post