In layout I am getting some value:
$quote = Quotes::model()->findAll(array('order'=>'id DESC', 'limit'=>1));
And it works Ok, no matter it is a bad practice to call model from view. In another layout in the same folder I cant do the same. If it matters, this layouts shows on the same page. I am responding straight to the Model and the Controller doesnt render any variables to view. Is there a way to send this var to custom layout or view?
You can create a method inside your controller that will return the value you need, and then you can call this method from view. Or if you are using $this->render() inside your view, then you just have to pass this variable forward to your custom view: $this->render('quotes',$quotes);
I put this line before $quote
and it worked!
Yii::import('application.modules.quotes.models.*');
Not sure, how it works, maybe this is my particular case.
I don't think that put the model inside the views/layout directly is the best practice. For some reason, I put a public variable, called $settings inside my Controller.php and put it inside the protected/components/
class Controller extends CController {
protected $settings = array();
public function init() {
$this->settings = Settings::model()->getAllSettings();
}
public function getSetting($key = '')
{
if (isset($this->settings[$key]))
{
return CHtml::decode($this->settings[$key]);
}
return NULL;
}
}
So inside my layout (main.php), I would do it this way.
<h1>Welcome to <?php echo $this->getSetting('brand_name');?>
The real code may look more complicated than the above, but I hope it helps you a little bit.