Showing results for 
Search instead for 
Did you mean: 

Join two tables cms/page and cms/page_store

Join two tables cms/page and cms/page_store

I will try get all pages assign to the website with name


$collection = Mage::getModel('cms/page')->getCollection();
       array('cps' => $collection->getTable('cms/page_store')),
       'cps.page_id = main_table.page_id',

 but after the query I receive on my page such message


Item (Mage_Cms_Model_Page) with the same id "9" already exist


as a result I want receive something like that

About Us    about-magento-demo-store    2 columns with right bar    All Store Views Enabled Mar 13, 2015 1:30:07 AM Mar 13, 2015 1:30:07 AM

and other all available pages assign to website


I to do all this in my controller.


Re: Join two tables cms/page and cms/page_store

Hi @MaximR 


I'm not sure wether you are trying to either get all pages that are assigned to a specific store, or you want to show all pages with there assigned stores next to them.


If you want to get all stores assigned to one store the cms page collection have a method you can call to filter of unwanted pages:


$collection = Mage::getResourceModel('cms/page_collection')


If you want to get the store id's for a page when it goes through a collection you can use the lookupStoreIds method on the page model's resource object. I'm not sure if this is actually a dobbelt lookup. But check if the object already contains data on getStoreId method. Otherwise use this code:


$collection = Mage::getResourceModel('cms/page_collection');

foreach($collection as $page)
    $storeIds = $page->getResource()->lookupStoreIds($page->getId())


I hope this helps :-)