8

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?

2 Answers 2

17

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()
1

CMS Pages array with Links

$cms_arr = Mage::getModel('cms/page')->getCollection()->toOptionArray();   
$cms_pages[""] = "-Select CMS Page-"; 
foreach($cms_arr as $cms){ 
    $url = $this->getUrl($cms["value"]); 
    $cms_pages[$url] = $cms["label"]; 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.