好吧,你应该花点时间学习一下 Symfony,因为这是为 Prestashop 1.7 构建后端模块所需要的。
作为指针,你需要创建一个扩展CommonAbstractType的表单类,添加一个构建表单方法。例如:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$this->context = Context::getContext();
$parents = [
['id_category' => 2, 'name' => 'Home', 'children' => $this->getSubCategories(1, true, 2)]
];
$builder->add('category', CategoryChoiceTreeType::class, [
'choices_tree' => $parents,
'choice_value' => 'id_category',
'choice_children' => 'children',
'choice_label' => 'name',
'disabled_values' => $disabledCategories,
'label' => 'Choose a category'
])
然后添加检索数据的方法以填充表单字段。
然后在你的控制器中使用这个类并显示表单:
$form = $this->createForm(YourFormForm::class);
还要添加一个 processForm 来处理数据。
如上所述,这不是您需要了解 Symfony 工作流程的复制/粘贴情况。