Yii? Delete constraints

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.