Create () is used multiple times in a project only it is a form validation, but it is a good mistake, the heart of the pain to understand the context and use of the usage
One: Generate the data object through the Create () method or assignment method, and then write to the database
1 $model = D (' User '); 2 $model->create (); // Skip Specific auto-generation and validation judgments 3 $model->add ()
The 1:create () method also supports other ways to create data objects: For example, other data objects or arrays
1 $data[' name '] = ' Mike '; 2 $data[' sex '] = ' male '; 3 $user->create ($data);
2: Creation of completed data can be read and modified directly
The second action method of the 3:create can specify the state of the operation that creates the data, by default, whether the write or update operation is automatically determined
4: If automatic validation is not defined, the Create method return value is an array of data objects that are created complete
The 5:create method creates a data object that is saved in memory and is not actually written to the database until it is actually written to the database using the Add or Save method
Two: Used for writing: field () and create () to detect the legality of the fields (form submission)
1 $model->field (' title,email,content ')->create ();
The legal field is only title,email,content, and will be masked no matter what means the user adds other fields.
Three: Automatic verification, is the model layer provides a method of data validation, create data object when creating the automatic data validation: The concrete is divided into static and dynamic mode
Four: Create () while creating data objects, complete a series of work, workflow
Steps |
Description |
Return |
1 |
Get data Source (default is post array) |
|
2 |
Verifying the legitimacy of the data source (non-arrays or objects are filtered) |
Failed to return false |
3 |
Check field mappings |
|
4 |
Judging data status (new or edited, specified or automatically judged) |
|
5 |
Automatic data validation |
Failed to return false |
6 |
Form token validation |
Failed to return false |
7 |
form data Assignment (filtering illegal fields and string handling) |
|
8 |
Data Auto-complete |
|
9 |
Generate Data Objects (saved in memory) |
|
The above describes the TP in the headache indefinitely create, including the content, I hope that the PHP tutorial interested in a friend helpful.