1
我有此脚本如何更新现有的CMS页面通过安装脚本
$cmsPage = Array (
'title' => 'Test Page 1',
'root_template' => 'one_column',
'identifier' => 'testpage1',
'content' => "<p>Testowa sprawa czy działa update ? oooooooooooo</p>",
'is_active' => 1,
'stores' => array(1),
'sort_order' => 0
);
$collection = Mage::getModel('cms/page')->getCollection()->addFieldToFilter('identifier', 'testpage1');
$page = Mage::getModel('cms/page')->load($collection->getFirstItem()->getId());
$page->setData($cmsPage)->save();
如果与标识符“testpage1”存在CMS网页,脚本创建另一个具有相同标识符。有没有办法检查cmspage是否存在 - 如果是这样 - 更新?
好吧,它工作正常!但一如既往,我有另一个问题:-) 如果我们有几个具有相同标识符的静态页面(对于其他存储视图(多层存储)的expample) - 如何过滤标识符和存储togather(存储存储在cms/page_store) – user3245106
阅读“Mage_Cms_Model_Resource_Page_Collection :: addStoreFilter()”。它看起来像你可以做类似'Mage :: getModel('cms/page') - > getCollection() - > addFieldToFilter('identifier','testpage1') - > addStoreFilter(array('storeid1', 'storeid2'),true);'。检查功能了解更多有关参数的信息。 – Pete171