-
Notifications
You must be signed in to change notification settings - Fork 26
Using Models
Yo-An Lin edited this page Feb 5, 2017
·
3 revisions
After you wrote the config loader in your application, now you could start to manipulate records through the model you just defined.
To use it, simply use that class, and construct the object:
use MyApp\Model\Book;To create a new book, simply type:
$ret = Book::create([
'title' => 'Programming PHP',
'author' => 'PHP Hackers'
]);The $ret above is actually the result object, which may contain the generated
SQL, execution result, validation result or exception (if there is an error).
To check if there is an error, simply use:
if ( $ret->error ) {
// success operation...
echo $ret->message, "\n";
}
$primaryKeyId = $ret->key;