我在Zend Framework中製作博客。此時,我正在編輯頁面來編輯博客帖子。在編輯帖子時填充多選擇
我有一個多選擇元素。它從數據庫中獲取數據。這是一個帶有標籤的列表。 當我編輯博客帖子時,它顯示我的表單中填充了所有可能標籤的列表。現在,我想設置一些選定的值(屬於帖子的標籤,如同在數據庫中選擇的那樣)。
這可能嗎?
在我的形式我這樣做是爲了多與價值觀
//create form element
$tags = $this->createElement('multiselect','tags');
//get all tags out DB
$tags_model = new Application_Model_DbTable_Tags();
$tags_array = $tags_model->getAll();
//fill the element with the tags
foreach ($tags_array as $tag){
$tags->addMultiOption($tag['id'], $tag['name']);
}
控制器在那裏我打電話的形式進行選擇: 它從博客帖子獲取數據並填充它的形式。
$blogpost = new Application_Model_DbTable_Blogposts();
$data = $blogpost->load($id);
$form->populate($blogpost->load($id));
SOLUTION:
$tags->setValue(array(1,4));
我必須在這裏寫的解決方案,因爲:
"Oops! Your answer couldn't be submitted because:
Users with less than 100 reputation can't answer their own question for 8 hours after asking. You may self-answer in 7 hours. Until then please use comments, or edit your question instead."
我會說是的,但既然你沒有向我們展示任何標記或代碼,它不會是明確的。 – RageZ 2011-12-23 09:23:50