0

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

1
  • 4
    It is more likely you have a design problem, try refactor your code. Data should be Model not controller. Commented Oct 21, 2009 at 10:09

1 Answer 1

2

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.