Yii? Delete constraints
Data table category: category_id category_titlesubcategory: subcategory_id subcategory_category (associated with category_id) when deleting data in the category table, make sure that the category_id does not exist in the subcategory_category table controller: public function actionDelete) {if (Yii: app ()-> request-> isPostRequest) {$ model = $ this-> loadModel ($ id); $ results = Category :: getSubCategorySet ($ id); // If you want to check whether the current category_id exists in subcategory_category/, you must notify the user. // here, an exception is thrown to remind the user, but I do not want an error number Or you have a better way to tell me 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 shocould not redirect the browser if (! Isset ($ _ GET ['Ajax ']) $ this-> redirect (isset ($ _ POST ['returnurl'])? $ _ POST ['returnurl']: array ('admin '));}}
Reply to discussion (solution)
You can change the view with the exception to remove the error number.
You can change the view with the exception to remove the error number.
The view with the exception is removed from the error number. this cannot be found.
You can change the view with the exception to remove the error number.
The view with the exception is removed from the error number. this cannot be found.
Will some content be displayed after an exception? There will be a default view called error or something.
Does not display the error label in that view meet your requirements?
SiteController. phppublic function actionError () {if ($ error = Yii: app ()-> errorHandler-> error) {if (Yii: app ()-> request-> isAjaxRequest) echo $ error ['message']; // If this parameter is removed, no Error message is displayed, but the error number is still in error: 400 else $ this-> render ('error ', $ error) ;}} there is an error in the site View. php deletion does not affect