5

In System->Configuration->Web->Default Pages I can set the default homepage and others.
I can even set different homepages on different store views. So far so good. That's very useful.
But here is what I don't understand.
The dropdown that allows me to select the pages looks like this: (generated by Mage_Cms_Model_Resource_Page_Collection::toOptionIdArray).

<select class=" select" name="groups[default][fields][cms_home_page][value]" id="web_default_cms_home_page">
    <option value="no-route">404 Not Found 1</option>
    <option value="home">Home page</option>
    <option value="home|5">Home page</option>
    ...
</select>

As you can see, when I hage 2 pages with the same identifier (home) the second one has the value identifier|page_id. The rest just use the identifier.

Now on the frontend, when the homepage should be rendered, the config value is read and passed to the Mage_Cms_Helper_Page::_renderPage method, that renders the page.

But in the method mentioned above this is how the page is determined:

   if (!is_null($pageId) && $pageId!==$page->getId()) {
        $delimeterPosition = strrpos($pageId, '|');
        if ($delimeterPosition) {
            $pageId = substr($pageId, 0, $delimeterPosition);
        }
        $page->setStoreId(Mage::app()->getStore()->getId());
        if (!$page->load($pageId)) {
            return false;
        }
    }

So the id after | is never used.
Is there any advantage of generating the options like this identifier|page_id that I'm missing?
It seams to me that it would have worked fine with only the page identifier or just the page id as option values.

  • Magento requires unique keys for the colllection? – Amasty Aug 8 '14 at 8:36
  • @Amasty. This has nothing to do with collections. The toOptionIdArray method, just generates and array. – Marius Aug 8 '14 at 8:39
  • 1
    Otherwise you would have several options with the same value in the backend, so the preselected value could not be determined. – Thorsten Aug 8 '14 at 9:58
  • This is just only for determining the selected and saved option on the "Default Pages Configuration" area. While rendering the page, the page identifier and it's store view is required. – mageUz Aug 8 '14 at 11:20
  • @mageUz. ha. That simple. It makes sense. Please post your comment as an answer. But still...this would have worked nicely with ids instead of page identifiers. – Marius Aug 8 '14 at 11:24
1

This is just only for determining the selected and saved option on the "Default Pages Configuration" area. While rendering the page, page identifier and it's store view is required. This would have worked with ids, but it is more clear (only for developer) using unique route identifier rather than a number, eg. to load page/static block by identifier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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