Can anyone tell me how to insert one view dynamically(may be depending on the database value) inside another? I tried it using renderPartial() as follows:
public function actionMyView()
{
$myViewObj = new MyViewForm();
$showObj = new ShowForm();
$output1 = $this->renderPartial('MyView',array('myViewObj'=>$myViewObj),true,false);
$output2 = $this->renderPartial('show',array('showObj'=>$showObj),true,false);
$layout=Yii::app()->layout;
$layoutFile=$this->getLayoutFile($layout);
$output=$this->renderFile($layoutFile,array('content1'=>$output1,'content2'=>$output2));
$this->processOutput($output);
}
But it is giving following error:
session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at D:\xampp\htdocs\partialRenderDemo\protected\views\layouts\main.php:6)
I found the solution to this issue on google, but applying those solutions does not seem to work. So, can anyone tell may be other way to achieve the task of inserting one view inside other?
I also have a similar problem. I have a view that looks like this:
<div id="timeform">
Here's a form to enter some time for a timetracker. It has a juidatepicker that onselect calls updateDayReport(d).
</div>
<div id="dayreport">
<?php $this->actionReportDay($date); ?>
</div>
<script type="text/javascript">
/*<![CDATA[*/
function updateDayReport(d) {
jQuery.ajax({
'url': '<?php echo $this->createUrl('reportDay') ?>&date='+d,
'cache':false,
'success':function(html){ jQuery("#dayreport").html(html); }
});
}
I want #dayreport filled on first page load. So i call the same action actionReportDay($date) that later will produce my AJAX response. That way i don’t need duplicate code to fetch the current time entries in the two actions.
<?php
public function actionReportDay($date=null)
{
if ($date===null)
$time=isset($_GET['date']) ? strtotime($_GET['date']) : null;
else
$time=strtotime($date);
// Get time entries for current user
$criteria=new CDbCriteria;
// ... set up criteria and fetch data here
$this->renderPartial('reportDay',array(
'timeList'=>$timeList,
'date'=>date('d.m.Y',$time)
));
}
This works great so far. Questions are now:
Is it o.k. to call a action from another view, if that action always uses renderPartial?
And can i change the action's signature to accept an optional parameter like above?
Yes, that problem is tricky. I'm still thinking of a way to solve it nicely. Will try to get it done by the release of 1.0.2. Maybe you can also help to think about it?