我有一个任务:
从前端静态块保存。
我试过的代码是
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包含在数据中?
答案 0 :(得分:0)
问题在于保存功能需要'store'键,而不是'store_id'。
$model->setData('stores',$model['store_id']);