Home > Backend Development > PHP Tutorial > yii?删除约束

yii?删除约束

WBOY
Release: 2016-06-20 12:46:45
Original
895 people have browsed it

数据表category: category_id category_titlesubcategory:subcategory_id subcategory_category(与category_id关联)      在删除category表的数据时,要确保category_id在subcategory_category中不存在控制器: public function actionDelete($id)    {        if(Yii::app()->request->isPostRequest)        {            $model=$this->loadModel($id);            $results = Category::getSubCategorySet($id);             //查找当前category_id是否在subcategory_category中存在                        //存在的话,就要提醒用户            //我这里是通过抛异常来提醒用户的,但我不想要错误编号的出现            //或者你们有更好的方法可以告诉我            if($results!=0){                throw new CHttpException(400,'This title is use on sub-category management');            }else{                $model = $this->loadModel($id);                $model->category_status = 'D';                if ($model->validate()) {                    $model->save();                }                // $model->delete();                // 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'));            }        }
Copy after login


回复讨论(解决方案)

你改下异常的那个view去掉错误编号好了

你改下异常的那个view去掉错误编号好了



异常的那个view去掉错误编号,这个找不到


你改下异常的那个view去掉错误编号好了



异常的那个view去掉错误编号,这个找不到



不是异常之后还是会显示一些内容吗?会有个默认的view,叫error还是什么的.
在那个view里把错误标号不显示是不是可以满足你要求?


SiteController.phppublic function actionError()	{	    if($error=Yii::app()->errorHandler->error)	    {	    	if(Yii::app()->request->isAjaxRequest)	    		echo $error['message'];                        //去掉这个就不会显示错误信息    但错误编号还在   Error:400	    	else	        	$this->render('error', $error);	    }	}site视图下有 error.php 整个删掉都没影响
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template