【发布时间】:2015-03-09 01:18:53
【问题描述】:
在我的模型中,我有一些自定义错误消息。
这只是我的代码的一部分:
if (!array_key_exists($target, $this->errors)) {
$this->errors = [ $target => '<div class="alert alert-danger" role="alert">Sorry, we could not connect to your <strong>'. $target .' database</strong>. Plese check your entries and try connecting again.</div>' ];
}
// There is no connection. Display the right error message and return null
if (count($this->errors > 0)) {
if (count($this->errors == 0)) {
echo array_values($this->errors)[0];
}
elseif (count($this->errors == 1)) {
echo '<div class="alert alert-danger" role="alert">Sorry, we could not connect to both of your databases. Plese check your entries and try connecting again.</div>';
}
elseif (count($this->errors > 1)) {
echo '<div class="alert alert-danger" role="alert">Warning: There is an unknown error. For more information please contact the owner of this website.</div>';
}
return null;
echo '<Form Layout>';
}
else {
return $this->result;
}
我实际上并不想在我的模型中回显这些错误消息。那么将它们发送到视图的最佳方式是什么?
【问题讨论】:
-
最好的方法是处理控制器中的错误,然后将必要的消息发送到视图。
标签: php codeigniter view model