2013-07-09 3 views
3

Я хочу добавить поле config в свой экземпляр magento. Вы должны иметь возможность хранить в нем блок cms.Что такое source_model для выбора блока cms в magento?

<block translate="label"> 
    <label>Cms block</label> 
    <frontend_type>select</frontend_type> 
    <source_model>???</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> 

Но я нашел только модель для страниц системе центра инерции (adminhtml/system_config_source_cms_page).

Что такое source_model для cms блоки?

ответ

6

Я думаю, что класс Mage_Cms_Model_Resource_Block_Collection отлично работает для этого:

    <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> 
+0

Это отличное решение, потому что оно вписывается в базовую функциональность супер метода 'Varien_Data_Collection :: toOptionArray' и иллюстрирует гибкость всех коллекций Magento в контексте формы администратора. –

4

Есть не любые, но вы можете сделать ваше:

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; 
    } 
} 
+0

Большое спасибо! :) – Simon

2

Создайте свой собственный источник model-

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> 
2

Вы можете использовать ту же модель, что и для поля статического блока категории: Catalog_Model_Category_Attribute_Source_Page aka catalog/category_attribute_source_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> 
Смежные вопросы