我看到了帖子Where are Magento static CMS blocks stored?的以下答案,关于在Magento中以编程方式使用PHP生成cms / blocks。
我将代码更改为以下
$newBlock = Mage::getModel('cms/page')
->setTitle('Test CMS Page Title')
->setContent('Hello I\'m a new cms page.')
->setIdentifier('this-is-the-page-url')
->setIsActive(true)
->save();
......它有效。我看到后端的CMS页面区域中显示了一个新页面。
我需要添加的是能够设置CMS / Page中其他字段的内容。即:
字段。这些字段目前是空白的。到目前为止,我还没有把这一部分搞清楚。
谢谢,
答案 0 :(得分:37)
你去:
$cmsPageData = array(
'title' => 'Test CMS Page Title',
'root_template' => 'one_column',
'meta_keywords' => 'meta,keywords',
'meta_description' => 'meta description',
'identifier' => 'this-is-the-page-url',
'content_heading' => 'content heading',
'stores' => array(0),//available for all store views
'content' => "Hello I'm a new cms page."
);
Mage::getModel('cms/page')->setData($cmsPageData)->save();
数组的键是cms_page
表的字段名称(检查数据库)。要知道该值,我手动创建我想要的cms页面,然后在db中查看该条目的值。