以编程方式在Magento中创建CMS /页面

Kyl*_*ger 17 php meta magento content-management-system

我在帖子中看到以下答案Magento静态CMS块存储在哪里?关于在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();
Run Code Online (Sandbox Code Playgroud)

......它有效.我看到后端的CMS页面区域中显示了一个新页面.

我需要添加的是能够设置CMS/Page中其他字段的内容.即:

  • 布局(尝试设置为1列)
  • meta关键字
  • 元描述

领域.这些字段目前是空白的.到目前为止,我还没有把这一部分搞清楚.

谢谢,

OSd*_*ave 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();
Run Code Online (Sandbox Code Playgroud)

数组的键是cms_page表的字段名称(检查数据库).要知道值,我手动创建我想要的cms页面,然后在db中查看此条目的值.