分类
后端

Magento2 控制器写法

<?php
namespace Maijindou\FormAgent\Controller\Index;
use Magento\Framework\App\Action\Context;
class Index extends \Magento\Framework\App\Action\Action
{
    protected $_pageFactory;

    public function __construct(Context $context, \Magento\Framework\View\Result\PageFactory $pageFactory)
    {
        $this->_pageFactory = $pageFactory;
        parent::__construct($context);
    }

    public function execute()
    {
        try {
            $this->messageManager->addSuccessMessage(__('submit successfully'));
        } catch (\Magento\Framework\Exception\LocalizedException $e) {
            $this->messageManager->addError(__($e));
        }
        $resultRedirect = $this->resultRedirectFactory->create();
        $resultRedirect->setPath('agent/index/ceshi');
        return $resultRedirect;
    }
}