create() публичный Метод

1. create method calls beforeCreate to trigger events or filter arguments. 2. it runs filterArrayWithColumns method to filter arguments with column definitions. 3. use currentUserCan method to check permission. 4. get column definitions and run filters, default value builders, canonicalizer, type constraint checkers to build a new arguments. 5. use these new arguments to build a SQL query with SQLBuilder\QueryBuilder. 6. insert SQL into data source (write) 7. reutrn the operation result.
public create ( array $args, array $options = [] ) : Result
$args array data
$options array
Результат Result operation result (success or error)
Пример #1
0
 /**
  * array fgetcsv ( resource $handle [, int $length = 0 [, string $delimiter = "," [, string $enclosure = '"' [, string $escape = "\" ]]]] ).
  */
 public function importResource($fd, $unsetPrimaryKey = false)
 {
     $schema = $this->model->getSchema();
     if ($this->columnMap) {
         $columnNames = $this->columnMap;
     } else {
         $columnNames = fgetcsv($fd);
     }
     while (($fields = fgetcsv($fd)) !== false) {
         $args = array();
         foreach ($columnNames as $idx => $columnName) {
             $columnValue = $fields[$idx];
             $args[$columnName] = $columnValue;
         }
         if ($unsetPrimaryKey) {
             if ($pk = $schema->primaryKey) {
                 unset($args[$pk]);
             }
         }
         $ret = $this->model->create($args);
     }
 }