slevin10
(Slevin10)
1
im try to keep all update history
so in my controller i rote:
public function actionUpdate($id)
{
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Activity']))
{
$oldModel=new Activity;
$oldModel->attributes=$model->attributes;
$model->attributes=$_POST['Activity'];?>
<?php
$maxActivNumber = Yii::app()->db->createCommand()
->select('max(activity_code) as max')
->from('tbl_activity')
->queryScalar();
$model->activity_code = $maxActivNumber + 1;
$oldModel->save();
?>
<?php if($model->save())
{....
it save the new parmeters whith the new activity_code
but don’t save $oldModel at all
why?
Keith
(Kburton)
2
I suspect that $oldModel isn’t passing validation. Perhaps you have an attribute that is required but that you haven’t provided.
For debugging purposes, see what happens when you do this:
if (!$oldModel->save())
{
var_dump($oldModel->errors);
die;
}
slevin10
(Slevin10)
3
well u right!
it not pass validation of 2 rules but how it can be? and what i can do? can i save it whithout check validation?
Keith
(Kburton)
4
Yes, pass false as the first parameter of the save() method.
slevin10
(Slevin10)
7
ok try it. dont give errore but not save either 
Keith
(Kburton)
8
What validation errors were you getting when you used var_dump?
slevin10
(Slevin10)
9
Keith thenks it solved! and its thenks to U!
public function actionUpdate($id)
{
$newmodel=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Activity']))
{
$model = new Activity;
$oldModel=$this->loadModel($id);
$model->attributes=$_POST['Activity'];?>
<?php
$maxActivNumber = Yii::app()->db->createCommand()
->select('max(activity_code) as max')
->from('tbl_activity')
->queryScalar();
$model->activity_code = $maxActivNumber + 1;
$oldModel->date_end=$model->date_start;
if (!$oldModel->save(false))
{
var_dump($oldModel->errors);
die;
}
?>
<?php if($model->save())
{.....
.....
$this->render('update',array(
'model'=>$newmodel,
));
}
i have enather issue im trying to set theend time of the oldmodel as day before the newmodel
$oldmodel->date_end=$model->date_start-1
its not realy work 
can u help me whit that too?