我想創建只讀隱藏字段。現在我有場,看起來像這樣:如何避免從symfony表單寫回數據?
$builder
->add('question_category_id', HiddenType::class);
和實體有方法:
public function getQuestionCategoryId() {
return $this->getQuestion()->getQuestionCategory()->getId();
}
節省我之後得到了以下錯誤:
Neither the property "question_category_id" nor one of the methods "addQuestionCategoryId()"/"removeQuestionCategoryId()", "setQuestionCategoryId()", "questionCategoryId()", "__set()" or "__call()" exist and have public access in class "Entity\UnitQuestionAnswer".
我可以添加虛擬方法
public function setQuestionCategoryId($id) {
return $this;
}
但它是不正確的方式。
如何創建只讀隱藏字段,或避免從實體寫回數據?
你想用只讀的隱藏字段做什麼? –
@JaredFarrish,按模板中的類別排列問題。 – sectus
[驗證symfony2形式與額外的字段]可能的副本(http://stackoverflow.com/questions/10868859/validating-symfony2-forms-with-extra-fields) –