【发布时间】:2025-12-24 21:15:06
【问题描述】:
在许多控制器中,我需要验证一个对象(在 URL 中传递的 ID)是否存在。
实际上每个控制器都有这个骨架:
public function my_page($id){
$object = $this->Object_model->getObject($id);
if($object == NULL){ // If id mentions a non-existant object, redirect to home
redirect("home");
}
/** MYCONTROLLER **/
}
这是最好的方法,最干净的方法吗?
其他一些选项是帮助器/模型方法/控制器方法...我不知道 PHP 的哲学是什么。
【问题讨论】:
标签: php codeigniter doctrine-orm