What is phpmassassignment? How to translate Chinese?

Source: Internet
Author: User
What is phpmassassignment? What is php mass assignment? How can I translate mass assignment into Chinese?

Reply content:

What is php mass assignment? How can I translate mass assignment into Chinese?

In the past 12 years, this concept was first proposed in Ror. Later Laravel proposed this concept.

This means that when you create a new data entry in the database, there are unnecessary (not) update data without special code (filter) in this case, it may be maliciously updated (created ).

I think it can be translated:Batch assignment

Refer:
Ror;
Laravel's answer above;
The answer above StackOverFlow;
Special explanation;

Example:

Mass assignment is when you send an array to the model creation, basically setting> a bunch of fields on the model in a single go, rather than one by one, something> like:

$ User = new User (Input: all ());
(This is instead of explicitly setting each value on the model separately .)

You can use fillable to protect which fields you want this to actually allow for> updating.

Let's say in your user table you have a field that is user_type and that can have> values of user/admin

Obviusly, you don't want users to be able to update this value. in theory, if you> used the above code, someone cocould inject into a form a new field for user_type and> send 'admin' along with the other form data, and easily switch their account to an> admin account... bad news.

By adding:

$ Fillable = array ('name', 'Password', 'email ');
You are ensuring that only those values can be updated using mass assignment

To be able to update the user_type value, you need to explicitly set it on the model and save it, like this:

$ User-> user_type = 'admin ';
$ User-> save ();

Mass:
The masses and the masses; large-scale and centralized
Translate mass assignmentCentralized assignmentIt is more appropriate.

P.s. LZ uses the Laravel framework, right? See http://stackoverflow.com/questions/22279435/what-does-mass-assignment -...

Laravel5 recently read this article. I usually do not translate.

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.