PhalconDb, PhalconDbAdapterPdo, and PhalconDbAdapterPdoMysql are database operations in phalcon. I have read these questions and I have not found any methods for obtaining the corresponding errors after database execution errors. I don't know what is going on. Do you know? Phalcon \ Db, Phalcon \ Db \ Adapter \ Pdo, Phalcon \ Db \ Adapter \ Mysql in Phalcon. I have read these questions and I have not found any methods for obtaining the corresponding errors after database execution errors. I don't know what is going on. Do you know?
Reply content:
Phalcon \ Db, Phalcon \ Db \ Adapter \ Pdo, Phalcon \ Db \ Adapter \ Mysql in Phalcon. I have read these questions and I have not found any methods for obtaining the corresponding errors after database execution errors. I don't know what is going on. Do you know?
- Assume that you have registered the "falsh" service:
php
/** 1. Register the flash service with custom CSS classes */$di->set('flash', function() { $flash = new \Phalcon\Flash\Direct(array( 'error' => 'alert alert-danger callout callout-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning' )); return $flash;});
- Take \ Phalcon \ Mvc \ Model as an example. In the controller:
php
if ($Article->save()) { $this->flash->success($Article->title . 'has been updated'); } else { foreach ($Article->getMessages() as $message) { $this->flashSession->error($message); } return $this->response->redirect($paginateUrl); $this->view->disable(); }
- Of course, you can also customize the verification information:
php
public function validation() { $this->validate(new Uniqueness(array( 'field' => 'slug', 'message' => 'The slug already exists in other articles,please modify the article title' ))); if ($this->validationHasFailed() == true) { return false; } }
For working with models
$robot = new Robots();$robot->type = "mechanical";$robot->name = "Astro Boy";$robot->year = 1952;if ($robot->save() == false) { echo "Umh, We can't store robots right now: \n"; foreach ($robot->getMessages() as $message) { echo $message, "\n"; }} else { echo "Great, a new robot was saved successfully!";}
For phql
$phql = "INSERT INTO Cars VALUES (NULL, 'Nissan Versa', 7, 9999.00, 2012, 'Sedan')";$result = $manager->executeQuery($phql);if ($result->success() == false){ foreach ($result->getMessages() as $message) { echo $message->getMessage(); }}