【发布时间】:2015-10-03 15:50:49
【问题描述】:
如果我的模型抛出异常,我想在我的 $message 成员中添加一条消息。
我得到了控制器的异常,但我不知道如何在视图中捕获它。
这是我正在尝试创建的示例。
// This is in my controller //
try {
if ($this->registerModel->doRegister($credentials) == true) {
echo "success";
}
} catch (userAlreadyExistException $e){
throw $e; // I want this to my view
}
// This is in my Model //
public function doRegister($credential)
{
if(true){
throw new userAlreadyExistException();
}
return true;
}
// This is my view //
public function getExceptions(){
try{
} catch (userAlreadyExistException $e) {
$this->message = "User already exist in the database";
}
//I also have this in a own class
class userAlreadyExistException extends Exception {}
}
【问题讨论】:
标签: php exception model-view-controller