문제

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, :-(

도움이 되었습니까?

해결책

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();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top