Question

Is it possible to instantiate a Controller class within another controller class using the Yii Framework

For example I have controller Student and and method actionShow of class student I have the following

public function actionShow()
    {  

        $student = $this->loadStudent();

        $studentContact = new Student_ContactController;

        //Checking if there was an ajax request
        if(Yii::app()->request->isAjaxRequest){
            $this->renderPartial('show',array(
                'student'=>$student,

            ));
        }else{
            $this->render('show',array(
                'student'=>$student,
            ));
        }



    }

Is it possible to include this action in the method $studentContact = new Student_ContactController;

Getting errors, :-(

Was it helpful?

Solution

I do not know the Yii framework, but as it is an MVC framework, then getting data should be part of the model, therefore $studentContact should be an instance of a model, not of a controller.

If you really want to instanciate an instance of a controller then call the constructor with brackets:

    $studentContact = new Student_ContactController();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top