开发者

Controller within another Controller

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_Cont开发者_开发技巧actController;

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜