Domanda

I have a Register controller that inherits from Controller that inherits from CController.

When i use __construct() it fails to render the view.

I tried adding parent::_construct($this->getUniqueID()) in the end of the function but no luck.

when i use init(), it's working.

Any idea how Yii is treating the construct vs init and why it can't find the rendered view?

EDIT:

class Controller extends CController {
}


class RegisterController extends Controller{
    public function init() {
    .
    .
    .
    }
}

this case is working, when replacing init with __construct it fails to render the view.

È stato utile?

Soluzione

In general I would not recommend overwriting the contruct on any object in Yii.

I know its a bit counter intuitive, but Yii works around conventions, and a convention here is to just put you initialization code in the init() method.

If you want to take a look at the Controller's source code you'll see that I does a lot under the hood, it needs to check for themes and controllers folders to resolve the view's path.

This mostly happens in the render method. but as rule of thumb, stick to the init() method.

Just stick to the convention and you will be fine, I can't think of a case that wouldn't fit well to just put aditional logic in the init method. its not like you are passing paramenters to the contructor, is it?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top