私はSymfony2で作業しています。EMPLOYEE エンティティ (特に文字列フィールド「カテゴリ」を持つ) と CONTRACT エンティティがあります。
だから、ここに私の問題があります:
従業員を編集したら、その従業員の契約を編集できます。
従業員がカテゴリ == 'worker' に属している場合、契約書にフィールド「salary」を追加したいのですが、カテゴリ = 'CEO' の場合、このフィールドを表示したくありません。
ここに私の ContractType があります:
class ContractType extends AbstractType
{
protected $employee;
function __construct(MyBundle\Entity\Employee $employee = null) {
$this->employee = $employee;
}
public function buildForm(FormBuilder $builder, array $options) {
$builder
->add('startDate');
if ($this->employee !== null && $this->employee->getCategory() == 'worker')
{
$builder
->add('salary', 'money', array('currency' => 'USD', 'required' =>false));
}
elseif ($this->employee !== null && $this->employee->getCategory() == 'CEO')
{
$builder->add('salary', 'hidden', array('required' => false));
}
}
}
これが私の contract_form.html.twig です:
{% if employee.category == 'worker'%}
<tr>
<td>{{ form_label(form.salary, "Salary : ") }}</td>
<td>{{ form_widget(form.salary) }}</td>
</tr>
{% endif %}
After editing a employee and setting him category=='worker', when I want to edit him a contract, I have the error :
Method "salary" for object "Symfony\Component\Form\FormView" does not exist in MyBundle:Contract:contract_form.html.twig"
このエラーで立ち往生しています。コードの何が問題なのかわかりません
助けてくれてどうもありがとう!