Hi,
I’m new with Yii but, even I have been improving a lot, I can’t resolve this problem.
I have a user form to process data from two different tables, Users and Employees (or ‘person’). This form has a select to chose one person. The purpose is when the user selects a Person from the list, automatically it have to change all the data fields corresponding to the person information. To do this I’ve tried to apply the changes with Ajax in the layer where I have all the data of the person. Also I’ve add a new function to get the new data, but my surprise is that Ajax always replaces the layer with a older page on the cache. I think I’ve done all to solve the problem with the cache (cache set to false, include a variable with aleatorial values in each trial, etc.) but nothing.
This is the code in the form:
...
<div class="row">
<?php echo $form->labelEx($modelUser,'id_personal'); ?>
<?php echo $form->dropDownList($modelUser,
'id_personal',
CHtml::listData($modelPersonal::model()->findAll(), 'id', 'nom'),
array( 'empty'=>'Sense persona vinculada',
'ajax' => array('type'=>'POST',
'cache'=>false,
'url'=>CController::createUrl('user/getPersonalInfo').'?s='.date('YmdHs'),
'data'=>array('id_user'=>$modelUser->id,
'id_persona'=>'js:this.value',
'time'=>date('YmdHs')),
'update'=>'#user-form' )); ?>
<?php echo $form->error($modelUser,'id_personal'); ?>
</div>
And the code in the controller:
public function accessRules()
{
return array(
array( 'allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('index','view','create','update','admin','delete','GetPersonalInfo'),
'roles'=>array('Admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
...
public function actionGetPersonalInfo(){
$id_usuari = $_POST['id_user'];
$id_personal = $_POST['id_persona'];
$modelUser=$this->loadModel($id_usuari); //echo $modelUser->id_personal;
$modelPersonal = $this->loadModel_Personal($id_persona); //echo '<br>'.$modelPersonal->email;
$modelUser->password = '';
$modelUser->password2 = '';
$this->renderPartial('application.views.user._form', array(
'modelUser'=>$modelUser,
'modelPersonal'=>$modelPersonal,
), false, true);
}
Sems that Ajax not make anithing with actionGetPersonalInfo(), but fails if it isn’t included in the accessRules().
The layer is replaced by a full page of any old framework page, and this happends with no particular browser I’ve tried with several (FF, IE …) Then I understand that is a problem with cache, but I can’t fix it.
Thank you very much for any help or idea,