2011-08-12 31 views
0

我有表:編輯幾個領域在一個表中的Symfony 1.4

id | cat_id | name 
1 | 1  | aaa 
2 | 1  | bbb 
3 | 2  | ccc 
4 | 3  | ddd 
5 | 2  | eee 
6 | 1  | fff 

我可以去site.com/table/edit/id/1 並告訴我輸入

name (id 1) [ aaa ] (i hide other field) 

,我可以編輯ID爲1怎能我做了一件事:

site.com/table/edit/cat_id/1 並告訴我:

name (id1) [ aaa ] 
name (id2) [ bbb ] 
name (id6) [ fff ] 

我可以編輯它們,並保存。這個怎麼做?

回答

1

你不打算用默認生成的表單來實現這一點。但是創建自己的表單非常容易(只需擴展sfForm並實現setup()函數)。然後在save()函數中添加您自己的邏輯。

僞代碼:

class myForm extends sfForm { 
    public function setup() { 
    $models = //; 

    foreach($models as $model) { 
     $this->addWidget(new sfWidgetFormInputText()); 
     $this->addValidator(new sfValidatorString()); 
    } 
    } 

    public function save() { 
    // loop through the widgets and save if valid. 
    } 
} 

編輯:嗯......我想你也可以創建一個表單,並添加所有的編輯形式子窗體。

+0

我該如何做到這一點?我可以創建自己的表格 –

+0

我加了一些僞代碼 –

+0

謝謝,但是這個$ this-> addWidget(new sfWidgetFormInputText()); 生成了相同的小部件。我必須在$模型中寫什麼?查詢我的表「TableTable.class」? –