Magento的。从自定义表单中保存静态块。无法存储商店

时间:2012-01-18 11:00:17

标签: magento content-management-system magento-1.5

我有一个任务:

从前端静态块保存。

我试过的代码是

public function savebannerAction(){
    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
    $post = $this->getRequest()->getPost();
    $block_id = $post['block_id'];
    $content = $post['content'];    

    $data = Mage::getModel('cms/block')->load($block_id)->getData();            
    $data['content'] = $content;
    Mage::getModel('cms/block')->load($block_id)->setData($data)->save();       
    $this->_redirectUrl($_SERVER['HTTP_REFERER']);
}

简单地说

public function savebannerAction(){
    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
    $post = $this->getRequest()->getPost();
    $block_id = $post['block_id'];
    $content = $post['content'];    
    Mage::getModel('cms/block')->load($block_id)->setContent($content)->save();         
    $this->_redirectUrl($_SERVER['HTTP_REFERER']);
}

但是我得到的两种方式是:内容被保存,但商店被空转。所以阻止从目前选定的商店中删除。或者我还应该将form_key包含在数据中?

1 个答案:

答案 0 :(得分:0)

问题在于保存功能需要'store'键,而不是'store_id'。

$model->setData('stores',$model['store_id']);