任何人都可以帮助我。它可能很简单,似乎我错过了一些东西。
我正在尝试在这里开发一个非常简单的模块。
在编辑部分,它没有选择Region
store_id 1是澳大利亚
代码:
<?php
class Ubt_Faq_Block_Adminhtml_Faq_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$x = Mage::registry('ubt_faq')->getData();
var_dump($x);
$form = new Varien_Data_Form();
$fieldset = $form->addFieldset('faq_form', array(
'legend' => Mage::helper('ubt_faq')->__('FAQ'),
'class' => 'fieldset-wide',
));
$fieldset->addField('faq_term', 'text', array(
'name' => 'faq_term',
'label' => Mage::helper('ubt_faq')->__('Term'),
'class' => 'required-entry',
'required' => true,
));
$fieldset->addField('faq_answer', 'textarea', array(
'name' => 'faq_answer',
'label' => Mage::helper('ubt_faq')->__('Answer'),
'class' => 'required-entry',
'required' => true,
));
if (!Mage::app()->isSingleStoreMode()) {
$fieldset->addField('store_ids', 'multiselect', array(
'label' => Mage::helper('ubt_faq')->__('Visible In'),
'required' => true,
'name' => 'store_ids[]',
'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(),
'value' => Mage::registry('ubt_faq')->getStoreId()
));
}
if (Mage::registry('ubt_faq')) {
$form->setValues(Mage::registry('ubt_faq')->getData());
}
$this->setForm($form);
return parent::_prepareForm();
}
}
在class Varien_Data_Form_Element_Multiselect extends Varien_Data_Form_Element_Abstract
$ value = $ this-&gt; getValue();在getElementHtml();
中变为null我认为这个$值不应为null,因为我已经为它赋值了。
答案 0 :(得分:1)
您好检查以下步骤可能会对您有所帮助
在Grid.php中
protected function _prepareCollection(){
$collection Mage::getModel("faq/faq")->getCollection();
foreach($collection as $link){
if($link->getStoreId() && $link->getStoreId() != 0 ){
$link->setStoreId(explode(',',$link->getStoreId()));
}
else{
$link->setStoreId(array('0'));
}
}
$this->setCollection($collection);
return parent::_prepareCollection();
}
添加列
$this->addColumn("store_id", array(
"header" => Mage::helper("faq")->__("Store View"),
"index" => "store_id",
"type" => "store",
"store_all" => true,
"store_view" => true,
"sortable" => true,
"filter_condition_callback" => array($this,
"_filterStoreCondition"),
));
在form.php
$fieldset->addField('store_id', 'multiselect', array(
'name' => 'store_id[]',
'label' => 'Store View',
'title' => '',
'required' => true,
'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true),
));
答案 1 :(得分:0)
尝试更新form.php
if (!Mage::app()->isSingleStoreMode()) {
$fieldset->addField('store_ids', 'multiselect', array(
'label' => Mage::helper('ubt_faq')->__('Visible In'),
'required' => true,
'name' => 'store_ids',
'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(),
));
}
答案 2 :(得分:0)
您需要在模块的数据库中添加表store_id,然后在模块数据控制器中添加保存操作。