以编程方式在Magento中创建CMS / Page [英] Programmatically creating a CMS/Page in Magento
问题描述
我看到以下对帖子的回答 Magento静态CMS块存储在哪里
I saw the following answer to the post Where are Magento static CMS blocks stored? regarding programatically using PHP generating cms/blocks in Magento.
我将代码更改为以下内容
I changed the code to the following
$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页面区域。
... and it works. I see a new page show up in the CMS Pages area in the backend.
我需要添加的是能够设置CMS / Page中的其他字段的内容。即:
What I need to add to this is the ability to set the content of the other fields in the CMS/Page. Namely:
- 布局(试图设置为1列)
- 元关键字
- 元描述
字段。这些字段目前为空。我到目前为止还没有能够计算出这部分。
fields. These fields are blank currently. I so far haven't been able to figure this part out.
感谢,
推荐答案
here you go:
$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
table(检查db)。并且要知道该值,我手动创建我想要的cms页面,然后在db中查看此条目的值。
The keys of the array are the name of the fields of the cms_page
table (check the db). And to know the value, I manually create the cms page I want and then see the value for this entry in the db.
这篇关于以编程方式在Magento中创建CMS / Page的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!