hi all, i wanna ask something
I have a db name CBC and a table name tbl_product_category and field like this:
-Id primary key,
-name unique,
-desc,
-channel_use unique,
-deleted
and i have a code in ProductCategoryController 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())
{
Controller::aftersave("ProductCategory",2,$row,true,$_POST['ProductCategory']);
$this->redirect(array('view','id'=>$row));
}
}
$this->render('create',array(
'model'=>$model,
));
}
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['ProductCategory']))
{
$data = Controller::beforeupdate("ProductCategory",$id,2);
$model->attributes=$_POST['ProductCategory'];
if($model->save())
{
Controller::afterupdate("ProductCategory",$id,$data,2);
$this->redirect(array('view','id'=>$model->id));
}
}
$this->render('update',array(
'model'=>$model,
));
}
/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'admin' page.
* @param integer $id the ID of the model to be deleted
*/
public function actionDelete($id)
{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
$connection = Yii::app()->db;
$sql = "update tbl_product_category set channel_use = null where id = $id";
$command = $connection->createCommand($sql)->execute();
$data = Controller::beforeupdate("ProductCategory",$id,2);
Controller::afterdelete($data,2);
Controller::deleted("ProductCategory",$id);
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
-
if i create a new name & new channel use, its working
-
if i create a new name & a channel that already in db,it can show a validation like this
1861
untitled.JPG
and it means its working, the update also can show a validation like that
- the problem is : if i delete one product category, i set the deleted in table tbl_product_category to 1, so the value its still in db,it not deleted. and i want create the product category use a name with i deleted it just now, and i use channel_use that already in db so its not working, its make error CDbException like this
1862
why not showing the validation but the error, can you check the code i wrote , its anything wrong in my code. thanks.