Hi,
I have the following problem: I have a site where I show some records and one form element: radiobuttons. I want to save this value which works quite well. The only problem I have is that I want to show the same site after saving but of course with the right value. Somehow it saves the record but shows the previously saved record. If I reload my site in the browser I get the right value.
my actionIndex:
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Curraudition');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
if(isset($_POST['Curraudition']))
{
$currA=Curraudition::model()->findbyPk($_POST['Curraudition']['id']);
$currA->attributes=$_POST['Curraudition'];
if(!$currA->save())
throw new CHttpException(404, 'The decision could not be saved.');
else
{
$dataProvider=new CActiveDataProvider('Curraudition');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
// $this->redirect(array('curraudition'));
}
}
}
part of my index.php:
<?php
$orchestra = Orchestra::Model()->findByAttributes(array('uid'=>Yii::app()->user->id));
$candidate = Candidate::Model()->findByAttributes(array('uid'=>Yii::app()->user->id));
if(isset($orchestra))
{
$this->breadcrumbs=array(
'Current auditions',
);
$this->menu=array(
array('label'=>'Create Curraudition', 'url'=>array('create')),
array('label'=>'Manage Curraudition', 'url'=>array('admin')),
);
?>
<h1>Current auditions</h1>
<?php
$oid = $orchestra->id;
$cond = 'orchestraId='.$oid;
$dataProvider1=new CActiveDataProvider('Jobad', array(
'criteria'=>array(
'condition'=>$cond,
),
));
$this->widget('application.components.widgets.ECListView', array(
'dataProvider'=>$dataProvider1,
'itemView'=>'application.views.jobad._view',
'model'=>'curraudition',
'condLeft'=>'jobId',
'condRight'=>'id',
'itemView2'=>'_view',
));
}
my _view.php:
<?php
$model=Candidate::Model()->findByPK($data->candidateId);
$model2=Curraudition::Model()->findByPK($data->id);
$caM=Curraudition::Model()->findByAttributes(array('candidateId'=>$model->id))
?>
<?php if (isset($model->photo)) { ?>
<div class="listview_photo">
<?php
$filepath = str_replace('\\','/',$model->photo);
if (ereg("^/",$filepath))
$filepath = substr($filepath, 1);
$filepathnew = str_replace('.jpg','xs.jpg',$filepath);
if (!is_file($filepathnew))
{
$image = Yii::app()->image->load($filepath);
$image->resize(110,85,Image::HEIGHT)->quality(100)->sharpen(20);
$image->save($filepathnew);
}
?>
<?php
echo CHtml::image(Yii::app()->request->baseUrl.'/'.$filepathnew);
?>
</div>
<?php } ?>
<div class="view">
<b><?php echo CHtml::encode($data->getAttributeLabel('Candidate')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($model->firstName.' '.$model->lastName), array('canprofile/view', 'id'=>$model->id)); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('Birthday')); ?>:</b>
<?php echo CHtml::encode($model->birthday); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('sex')); ?>:</b>
<?php echo CHtml::encode($model->sex); ?>
<br />
<?php $form=$this->beginWidget('application.components.ActiveForm', array(
'id'=>'curraudition-form',
'enableAjaxValidation'=>false,
)); ?>
<div class="row">
<?php echo $form->labelEx($model2,'decision'); ?><b>:</b>
<?php echo $form->radioButtonList($model2,'decision',array('j'=>'Yes','n'=>'No'),array('size'=>1,'maxlength'=>1)); ?>
<?php echo $form->hiddenField($model2,'id'); ?>
<?php echo CHtml::submitButton($model2->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<div class="row buttons">
</div>
<?php $this->endWidget(); ?>
</div>
and also part my extended version of CListView
public function renderItems()
{
echo CHtml::openTag('div',array('class'=>$this->itemsCssClass))."\n";
$data=$this->dataProvider->getData();
if(count($data)>0)
{
$owner=$this->getOwner();
$render=$owner instanceof CController ? 'renderPartial' : 'render';
foreach($data as $i=>$item)
{
$data=$this->viewData;
$data['index']=$i;
$data['data']=$item;
$data['widget']=$this;
$owner->$render($this->itemView,$data);
echo CHtml::openTag('div',array('class'=>'view_applicants'));
echo CHtml::openTag('div',array('class'=>$this->itemsCssClass))."\n";
$condRight = (string)$this->condRight;
$dataProvider2=new CActiveDataProvider($this->model, array(
'criteria'=>array(
'condition'=>$this->condLeft.'='.$item->$condRight,
),
));
$data2=$dataProvider2->getData();
if(count($data2)>0)
{
$owner=$this->getOwner();
$render=$owner instanceof CController ? 'renderPartial' : 'render';
foreach($data2 as $i=>$item)
{
$data2=$this->viewData;
$data2['index']=$i;
$data2['data']=$item;
$data2['widget']=$this;
$owner->$render($this->itemView2,$data2);
}
}
else
{
echo CHtml::openTag('span',array('class'=>'empty'));
echo CHtml::encode('There are no applicants yet.');
echo CHtml::closeTag('span');
}
echo CHtml::closeTag('div');
echo CHtml::closeTag('div');
}
}
else
{
echo CHtml::openTag('span',array('class'=>'empty'));
echo CHtml::encode('You don\'t have any upcoming auditions.');
echo CHtml::closeTag('span');
}
echo CHtml::closeTag('div');
}
I hope that someone could help me
schlydi