Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
什么';在magento中cms块选择器的源\u模型是什么?_Magento_Model_Magento 1.12 - Fatal编程技术网

什么';在magento中cms块选择器的源\u模型是什么?

什么';在magento中cms块选择器的源\u模型是什么?,magento,model,magento-1.12,Magento,Model,Magento 1.12,我想在我的magento实例中添加一个config字段。您应该能够在其中存储cms块 Cms块 选择 ??? 30 1. 1. 1. 但是我只找到了cms页面的模型(adminhtml/system\u config\u source\u cms\u page) cms块对应的源\u模型是什么?没有,但您可以: class Your_Module_Model_System_Config_Source_Cms_Block { protected $_options; publ

我想在我的magento实例中添加一个
config
字段。您应该能够在其中存储cms块


Cms块
选择
???
30
1.
1.
1.
但是我只找到了cms页面的模型(
adminhtml/system\u config\u source\u cms\u page


cms块对应的
源\u模型是什么?

没有,但您可以:

class Your_Module_Model_System_Config_Source_Cms_Block
{
    protected $_options;

    public function toOptionArray()
    {
        if (!$this->_options) {
            $this->_options = Mage::getResourceModel('cms/block_collection')
                ->load()
                ->toOptionArray();
        }
        return $this->_options;
    }
}

创建自己的源模型-

class Namespace_Modulename_Model_System_Config_Source_Cmsblock
{
    protected $_options;

    public function toOptionArray()
    {
        if (!$this->_options) {
            $this->_options = Mage::getResourceModel('cms/block_collection')
                ->load()
                ->toOptionArray();
        }
        return $this->_options;
    }
}
将其包含在系统xml中:

<block translate="label">
  <label>Cms block</label>
  <frontend_type>select</frontend_type>
  <source_model>modulename/system_config_source_cmsblock</source_model>
  <sort_order>30</sort_order>
  <show_in_default>1</show_in_default>
  <show_in_website>1</show_in_website>
  <show_in_store>1</show_in_store>
</block>

Cms块
选择
模块名称/系统配置源代码块
30
1.
1.
1.

您可以使用与类别静态块字段相同的模型:
Catalog\u model\u category\u Attribute\u Source\u Page
aka
Catalog/category\u Attribute\u Source\u Page

<block translate="label">
  <label>Cms block</label>
  <frontend_type>select</frontend_type>
  <source_model>catalog/category_attribute_source_page</source_model>
  <sort_order>30</sort_order>
  <show_in_default>1</show_in_default>
  <show_in_website>1</show_in_website>
  <show_in_store>1</show_in_store>
</block>

Cms块
选择
目录/类别属性源页面
30
1.
1.
1.

我认为class Mage\u Cms\u Model\u Resource\u Block\u集合在这方面非常有用:

                    <cms_block translate="label">
                      <label>Left template CMS block</label>
                      <frontend_type>select</frontend_type>
                      <source_model>cms/resource_block_collection</source_model>
                      <sort_order>0</sort_order>     
                      <show_in_default>1</show_in_default>
                      <show_in_website>0</show_in_website>
                      <show_in_store>0</show_in_store>
                    </cms_block>   

左模板CMS块
选择
cms/资源块集合
0
1.
0
0

这是一个很好的解决方案,因为它利用了超级方法的核心功能
Varien_Data_Collection::toOptionArray
,并说明了在管理表单的上下文中所有Magento集合的灵活性。Magento 2.4解决方案可在此处找到