phalcon中的数据库操作类Phalcon\Db,Phalcon\Db\Adapter\Pdo,Phalcon\Db\Adapter\Pdo\Mysql。这几个我看了,都没有数据库执行出错后获取相应错误的方法,不知道是怎么回事,有没有知道的啊?
2 回答
慕森王
TA贡献1777条经验 获得超3个赞
假设你已经注册"falsh"服务:php/**1.RegistertheflashservicewithcustomCSSclasses*/$di->set('flash',function(){$flash=new\Phalcon\Flash\Direct(array('error'=>'alertalert-dangercalloutcallout-danger','success'=>'alertalert-success','notice'=>'alertalert-info','warning'=>'alertalert-warning'));return$flash;});以\Phalcon\Mvc\Model为例,在controller里面:phpif($Article->save()){$this->flash->success($Article->title.'hasbeenupdated');}else{foreach($Article->getMessages()as$message){$this->flashSession->error($message);}return$this->response->redirect($paginateUrl);$this->view->disable();}当然,你也可以自定义验证信息:phppublicfunctionvalidation(){$this->validate(newUniqueness(array('field'=>'slug','message'=>'Theslugalreadyexistsinotherarticles,pleasemodifythearticletitle')));if($this->validationHasFailed()==true){returnfalse;}}
慕的地6264312
TA贡献1817条经验 获得超6个赞
如果是workingwithmodels则$robot=newRobots();$robot->type="mechanical";$robot->name="AstroBoy";$robot->year=1952;if($robot->save()==false){echo"Umh,Wecan'tstorerobotsrightnow:\n";foreach($robot->getMessages()as$message){echo$message,"\n";}}else{echo"Great,anewrobotwassavedsuccessfully!";}如果是phql则$phql="INSERTINTOCarsVALUES(NULL,'NissanVersa',7,9999.00,2012,'Sedan')";$result=$manager->executeQuery($phql);if($result->success()==false){foreach($result->getMessages()as$message){echo$message->getMessage();}}
添加回答
举报
0/150
提交
取消