17

我看到了帖子的以下答案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();

...它的工作原理。我看到后端的 CMS 页面区域出现了一个新页面。

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

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

字段。这些字段目前为空白。到目前为止,我还无法弄清楚这部分。

谢谢,

4

1 回答 1

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 中查看该条目的值。

于 2012-02-17T07:44:39.063 回答