hi all,i want to ask how to display error from controller?
i have a code like this in controller.php(the controller.php is a global function):
public function aftersave($nama,$tanda,$id,$set=false,$data='')
{
$sql1 = "select channel_use from tbl_product_category where channel_use = ".$data['channel_use']."";
$cek = $connection->createCommand($sql1)->queryScalar();
if($cek == null)
{
$sql = "update ".$tabel." set last_user = '".Yii::app()->user->first_name."', first_user = '".Yii::app()->user->first_name."', last_ip = '".$_SERVER['REMOTE_ADDR']."', first_ip = '".$_SERVER['REMOTE_ADDR']."', last_update = NOW(), first_update = NOW(), deleted = 0, `desc`='".$data['desc']."',channel_use = '".$data['channel_use']."' where id = $id";
$berita = "Create ".$nama." : Name : $current->name, desc : $current->desc, deleted : 0, channel_use : $current->channel_use ";
}
else
{
$error=1;
return $error;
}
}
and in ProductCategoryController the code is like this :
public function actionCreate()
{
$model=new ProductCategory;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['ProductCategory']))
{
$model->attributes=$_POST['ProductCategory'];
$row = Controller::kueri(2,$model);
if ($row == null)
{
if($model->save())
{
$last = Yii::app()->db->getLastInsertID();
Controller::aftersave("ProductCategory",2,$last);
$this->redirect(array('view','id'=>$model->id));
}
}
else //if($model->validate())
{
$cek = Controller::aftersave("ProductCategory",2,$row,true,$_POST['ProductCategory']);
if($cek == 1)
{
[color="#FF0000"]$this->render('index',array('model'=>$model));[/color]
}
else
{
$this->redirect(array('view','id'=>$row));
}
}
}
$this->render('create',array(
'model'=>$model,
));
}
and in the _form.php
its already have a coding like this <?php echo $form->errorSummary($model); ?>
i tried this code $this->render(‘index’,array(‘model’=>$model)) but its not working, i have error if i use this code.
thanks.