In An ORM instance, permission verification is required for the delete method. What are the advantages of this verification method?

Source: Internet
Author: User
Is it added to the controller? {Code...} is added to {code...}. If it is added to the controller, this permission verification must be added to each place that calls the delete method, which is easy to miss. If it is added to _ beforeDelete (), it will cause too much damage. Some instances... are added to the controller?

$posts = new Model()if($this->hasPermission()){  $posts->delete($key);}

Or add

function _beforeDelete(){  if($this->hasPermission()){    return true;  }  return false;}

If it is added to the controller, the permission verification must be added for each place that calls the delete method, which is easy to miss.

If it is added to _ beforeDelete (), it will cause too much damage. Some instance delete operations will be affected without permission verification.

Or are there other processing methods?

Reply content:

Is it added to the controller?

$posts = new Model()if($this->hasPermission()){  $posts->delete($key);}

Or add

function _beforeDelete(){  if($this->hasPermission()){    return true;  }  return false;}

If it is added to the controller, the permission verification must be added for each place that calls the delete method, which is easy to miss.

If it is added to _ beforeDelete (), it will cause too much damage. Some instance delete operations will be affected without permission verification.

Or are there other processing methods?

Of course, the business logic should be added to the business layer and Controller. There is no doubt.

If there is everywhere, you can use some encapsulation and use some design patterns to centralize the scattered verification code.

I personally think that the domain object is more elegant, and the verification logic will not be scattered.

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.