phalcon 怎么写原生的mysql
发布网友
发布时间:2022-05-22 05:22
我来回答
共1个回答
热心网友
时间:2024-03-06 17:34
假设你已经注册"falsh"服务:/**
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;
});
以\Phalcon\Mvc\Model为例,在controller里面:
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();
}
当然,你也可以自定义验证信息:
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;
}
}