In this tutorial i will show how to call a method from a class
first we should import the class.
after that we should instantiate the imported class.
then we can call method via instance.
Example,
class AnotherController extends Controller
{
public function __construct($id=NULL)
{
}
public function message()
{
return 'Message from Another Controller';
}
}
?>
Above lines shows a class(Controller). assume that this class is placed in side
the contollers folder.
we want to access method "message" from another controller.
solutioin is ,
public function messageFromAnotherClass()
{
Yii::import("application.controllers.AnotherController");
$another = new AnotherController();
return $message = $another->message();
}
first we should import the class.
after that we should instantiate the imported class.
then we can call method via instance.
Example,
class AnotherController extends Controller
{
public function __construct($id=NULL)
{
}
public function message()
{
return 'Message from Another Controller';
}
}
?>
Above lines shows a class(Controller). assume that this class is placed in side
the contollers folder.
we want to access method "message" from another controller.
solutioin is ,
public function messageFromAnotherClass()
{
Yii::import("application.controllers.AnotherController");
$another = new AnotherController();
return $message = $another->message();
}