我有一个静态块,我想通过通过cron运行的脚本进行更新。

我发现了如何以编程方式创建或检索一个块,但没有找到如何编辑现有块。

这可以检索一个块:

// Retrieve the layout object
$layout = Mage::getSingleton('core/layout');

// Generate a CMS block object
$block = $layout->createBlock('cms/block');

// Set the block ID of the static block
$block->setBlockId('my_block_id');

// Write the static block content to screen
echo $block->toHtml();

我想我这里缺少一些简单的东西,但是在此块上执行setContent()然后进行save()只会导致“无效的方法Mage_Cms_Block_Block::save”

最佳答案

按区块ID:

Mage::getModel('cms/block')->load($id)
  ->setData('content', 'Example content')
  ->save();

按标识符:
Mage::getModel('cms/block')
  ->getCollection()
  ->addFieldToFilter('identifier', 'my_block_id')
  ->load()
  ->setData('content', 'Example content')
  ->save();

09-25 17:02
查看更多