How to get a list of cms pages in Magento?

How to get a list of cms pages in Magento?

July 18, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to get a list of cms pages in Magento?

Getting a list of CMS pages in Magento involves accessing the CMS page model and converting it into an option array for use in your admin form. I’ll guide you through this process step-by-step.

What You’re Trying to Do

You want to create an admin form where the user can select a CMS page from a dropdown menu. To achieve this, you need to retrieve all CMS pages from the Magento database and convert them into a format that can be used in your form field.

What You’ve Tried

In your attempt, you tried using Mage::getSingleton('cms/page')->toOptionArray(). However, as you mentioned, toOptionArray() is not a valid function for the 'cms/page' model. This happens because the CMS page model doesn’t have this specific method built-in.

The Solution

To get an option array of CMS pages, we need to manually retrieve all CMS pages and create the options array ourselves. Here’s how you can do it:

  1. First, include the necessary Magento class files in your code:
include_once Mage::getConfig()->getOption('install_dir') . '/app/Mage.php';
Mage::app();
  1. Then, use the following code to retrieve all CMS pages and convert them into an option array:
$cmsPages = Mage::getModel('cms/page')->getCollection();

$optionArray = array();
foreach ($cmsPages as $page) {
    $optionArray[$page->getId()] = $page->getTitle();
}

In this code, we first get the Mage_Cms_Model_Resource_Page_Collection using Mage::getModel('cms/page')->getCollection(). This gives us a collection of all CMS pages.

We then loop through each page in the collection. For each page, we add an option to the $optionArray, where the key is the page ID (obtained with $page->getId()) and the value is the page title (obtained with $page->getTitle()).

  1. Finally, you can use this $optionArray in your form field like this:
$form->addField('cms_page_id', 'select', array(
    'label'     => Mage::helper('custom/data')->__('CMS Page'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'cms_page_id',
    'values'    => $optionArray, // Use the option array we created
    'value'     => $this->getCmsPageId()
));

Conclusion

By following these steps, you should now be able to get an option array of all CMS pages in Magento and use it in your admin form dropdown. This method ensures that your code is robust and handles the retrieval of CMS page data correctly.

Remember, when working with Magento models and collections, it’s important to understand their functionality and methods available for proper data manipulation. If you need more assistance or have any other questions about Magento development, feel free to explore our resources at Laravel Company. We provide a wide range of tutorials and guides on Magento development best practices.

Happy coding!

Database Admin Configuration

Our network