Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii Retrieve and store in a variable a renderPartial file

Tags:

yii

I have a php file under protected/views/directory_controller_name with formatting like that

<p>
<?php echo $model->title;?>
</p>
...

I display the file with classic method in the controller :

$this->render('filename',array('model'=>$model));

But know, I need to send an email with the same template/layout so I want to store the render of the file in an variable like

$msgHTML = $this->renderInternal('_items', array('model'=>$model));

But it doesn't work!

How can I get render view from a file and store in a variable? Is it possible?

I don't want to use:

$msgHTML = '<p>'.$model->title.'</p>'
...

Because the file is very long and I don't want to duplicate code!!!

like image 833
BasicCoder Avatar asked Oct 02 '11 16:10

BasicCoder


2 Answers

Don't use the renderInternal method, use renderPartial instead. Render internal is low level method and should not be used in such context. To catch the output just set the $return parameter to true:

<?php $output = $this->renderPartial('_subView', $dataArray, true); ?>
like image 94
emix Avatar answered Sep 23 '22 05:09

emix


$msgHTML = $this->renderInternal('_items', array('model'=>$model), true);

http://www.yiiframework.com/doc/api/1.1/CBaseController#renderInternal-detail

like image 42
ldg Avatar answered Sep 22 '22 05:09

ldg