如何更改輸入表單的屬性?如何更改doctrine2中的輸入值
我用這個輸入(productform.php)創建:
$this->add(array(
'name' => 'categoryId',
'attributes' => array(
'id' => 'categoryId',
'type' => 'hidden',
'value' => '',
),
));
在前面的頁面我鏈接的形式和設置的URL(....com/form/3
)的特殊價值。
在indexcontroller.php中,我得到表單$form = new ProductForm();
,並且想要編輯該值並從url中設置特殊值。
我的想法是$form->setAttribute('categoryId', 'value');
但這不起作用。
謝謝。
indexcontroller.php
...
$form = new ProductForm();
$form->setHydrator(new CategoryHydrator());
$form->bind(new Product());
$form->setAttribute('categoryId', 'value');
....
productform.php
...
class ProductForm extends Form
{
public function __construct()
{
parent::__construct('productForm');
$this->setAttribute('action', 'newproduct');
$this->setAttribute('method', 'post');
$this->add(array(
........
已更新。請具體說明您的問題。 – Bilal