Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of cms pages in Magento?

Tags:

magento

What i'm trying todo

I have created an admin form where the user needs to select a CMS page from a drop down.

What i have tried

$form->addField('cms_page_id', 'select', array(
'label'     => Mage::helper('custom/data')->__('CMS Page'),
'class'     => 'required-entry',
'required'  => true,
'name'      => 'cms_page_id',
'values'    => Mage::getSingleton('cms/page')->toOptionArray(),
'value'     => $this->getCmsPageId()
));

The idea is the code gets the an option array from the CMS model. However "toOptionArray" is an invalid function for the 'cms/page' model.

My Question

How can I get an option array of CMS pages for use in an admin form in Magento?

like image 942
woot586 Avatar asked Jun 29 '13 11:06

woot586


People also ask

What are CMS pages in Magento?

Magento 2 CMS Pages are the set of your Magento 2 website pages used for distributing content. Magento 2 enables you to create CMS pages for different purposes or translate CMS pages for different locales. You can even restrict some CMS pages visibility for a certain group of customers.

Where do I find pages in Magento?

You can it in the Magento admin panel: System > configuration. and here you can find each detail of the pages which have been called.

How do you call a CMS page in magento2?

login to magento admin. Open any cms page and write block code in content section. After using the block code phtml file will be called on cms page. If you want to call phtml file on all cms pages then you can create a layout file to achieve this.


1 Answers

With your code you are loading a new cms page model. To get a collection use following code and toOptionArray() will at least return something:

Mage::getModel('cms/page')->getCollection()->toOptionArray()
like image 59
Simon H Avatar answered Oct 24 '22 21:10

Simon H