【发布时间】:2026-02-16 17:25:01
【问题描述】:
在 Doctrine Record 对象中,我可以添加以下方法来验证数据:
protected function validate()
{
if (empty($this->first_name) && empty($this->last_name) && empty($this->company)) {
$this->getErrorStack()->add('company', 'You must fill in at least one of the following: First Name, Last Name, Company');
}
}
如何向附加的模板对象添加类似的代码?
【问题讨论】:
-
不明白。你能提供更多关于你想要做什么的信息吗?
-
@Timo,Doctrine 有行为。使用行为,我可以为多个模型分配功能。如何在行为中包含验证?如果您仍然不明白,请告诉我。另外,不明白的部分请详细说明。
标签: validation model doctrine behavior doctrine-1.2