How can I use renderPartial when I am in a model? Using $this is not allowed, and I’m not sure if I can do something like $item = new Controller(‘menu’).
How can I use renderPartial when I am in a model? Using $this is not allowed, and I’m not sure if I can do something like $item = new Controller(‘menu’).
Try using Yii::app()->controller.
Do not output anything directly from the model. Model should be used to retrieve/generate/process data in a presentation-independent way. Instantiate model in the controller, ask it for data, then use renderPartial to display the result.
MVC guide
That’s actually what a controller is for.
One of the few things - if not the only thing.
Put everything else in your model, but don’t let your model talk to the view - that’s the job of the controller.
In my project the controler is calling $model->email(), which triggers some code to send an email.
This code is in the Model because it independent of the controller, it depends only on the Model.
Therefore I put it in the model.
To generate the email, I wanted to use renderPartial.
What is the best thing to do then?
A model should not be able to send mails…This code is for a component. Check the documentation on how to create components
renderPartial can generate HTML body, and then can use email function to send out this body, thx.