本文整理汇总了PHP中Magento\Backend\Model\Session::setMageplazaBlogPostData方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::setMageplazaBlogPostData方法的具体用法?PHP Session::setMageplazaBlogPostData怎么用?PHP Session::setMageplazaBlogPostData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Backend\Model\Session
的用法示例。
在下文中一共展示了Session::setMageplazaBlogPostData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* run the action
*
* @return \Magento\Backend\Model\View\Result\Redirect
*/
public function execute()
{
$data = $this->getRequest()->getPost('post');
$resultRedirect = $this->resultRedirectFactory->create();
if ($data) {
$post = $this->initPost();
$post->setData($data);
$image = $this->uploadModel->uploadFileAndGetName('image', $this->imageModel->getBaseDir(), $data);
if ($image) {
$post->setImage('mageplaza/blog/post/image' . $image);
}
$tags = $this->getRequest()->getPost('tags', -1);
if ($tags != -1) {
$post->setTagsData($this->jsHelper->decodeGridSerializedInput($tags));
}
$topics = $this->getRequest()->getPost('topics', -1);
if ($topics != -1) {
$post->setTopicsData($this->jsHelper->decodeGridSerializedInput($topics));
}
if (!isset($data['categories_ids'])) {
$post->setCategoriesIds([]);
}
$this->_eventManager->dispatch('mageplaza_blog_post_prepare_save', ['post' => $post, 'request' => $this->getRequest()]);
try {
$post->save();
$trafficModel = $this->trafficFactory->create()->load($post->getId(), 'post_id');
if (!$trafficModel->getId()) {
$trafficData = ['post_id' => $post->getId(), 'numbers_view' => '0'];
$trafficModel->setData($trafficData);
$trafficModel->save();
}
$this->messageManager->addSuccess(__('The Post has been saved.'));
$this->backendSession->setMageplazaBlogPostData(false);
if ($this->getRequest()->getParam('back')) {
$resultRedirect->setPath('mageplaza_blog/*/edit', ['post_id' => $post->getId(), '_current' => true]);
return $resultRedirect;
}
$resultRedirect->setPath('mageplaza_blog/*/');
return $resultRedirect;
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (\RuntimeException $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addException($e, __('Something went wrong while saving the Post.'));
}
$this->_getSession()->setMageplazaBlogPostData($data);
$resultRedirect->setPath('mageplaza_blog/*/edit', ['post_id' => $post->getId(), '_current' => true]);
return $resultRedirect;
}
$resultRedirect->setPath('mageplaza_blog/*/');
return $resultRedirect;
}