1

谁能帮帮我吗。这可能真的很简单,好像我错过了一些东西。

我正在尝试在这里开发一个非常简单的模块。

在编辑部分,它没有选择区域

在此处输入图像描述

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->getValue(); 在 getElementHtml() 中为空;

我认为这个 $value 不应该为空,因为我已经为它赋值了。

4

3 回答 3

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),
 ));
于 2012-11-06T05:23:41.593 回答
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(),
       ));          
   }
于 2012-11-06T13:45:41.603 回答
0

您需要在模块的数据库中添加表 store_id,然后在模块数据控制器中添加保存操作。

于 2013-05-03T06:52:55.240 回答