Reputation: 611
I have a public function in model Yii:
public function test() {
echo 'I am working';
}
Now I want to call this function on view Yii. I wolud like to go through via controller instead of directly calling that function on view Yii.
So how can I call the function on view Yii? and what I have to do with controller before I call it on view Yii?
Upvotes: 2
Views: 8969
Reputation: 1341
I prefer to put it on your controller, like this
$model_result = MyModel::model()->test();
$this->render('view', array('model_result' => $model_result));
On your view.php
<div class="my_class" >
<?php echo $model_result;?>
</div>
Upvotes: 5
Reputation: 9340
View should not call any functions (unless perhaps formatting helper functions), controller should pass to the view whatever values it needs, including but not limited to a result of function/method call.
Upvotes: 0