Rourter动作工厂陷入无限循环

Rourter动作工厂陷入无限循环

本文介绍了Magento 2.1.2 Rourter动作工厂陷入无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发magento2中的模块.问题出在路由上,路由器返回$ this-> actionFactory-> create('Magento \ Framework \ App \ Action \ Forward');不会重定向到我的模块,控制器和代码中指定的操作;它会阻止一个异常,前端控制器达到了100个路由器匹配迭代.任何帮助将不胜感激.在此先感谢您!

public function match(\Magento\Framework\App\RequestInterface $request)
    {

 $identifier = trim($request->getPathInfo(), '/');

    $condition = new \Magento\Framework\DataObject(['identifier' =>   $identifier, 'continue' => true]);
    $this->eventManager->dispatch(
        'news_controller_router_match_before',
        ['router' => $this, 'condition' => $condition]
    );

    $identifier = $condition->getIdentifier();

    if ($condition->getRedirectUrl()) {

        $this->response->setRedirect($condition->getRedirectUrl());
        $request->setDispatched(true);
        return $this->actionFactory->create('Magento\Framework\App\Action\Redirect');
    }

    if (!$condition->getContinue()) {
        return null;
    }

    /*for main page */
    /*check identifier against news-configuration main page idendifier */

    //$mainIdentifier = $topic->getMainPageIdentifer();
     $mainIdentifier = 'news';

    if ($mainIdentifier == $identifier) {

        $request->setModuleName('news')->setControllerName('index')->setActionName('view');
         $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $identifier);
           return $this->actionFactory->create('Magento\Framework\App\Action\Forward');
    }



}
1 exception(s):
Exception #0 (LogicException): Front controller reached 100 router match iterations

Exception #0 (LogicException): Front controller reached 100 router match iterations
#0 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Interceptor.php(74): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#1 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Chain/Chain.php(70): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#2 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'requestPreproce...')
#3 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php(94): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#4 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#5 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'install')
#6 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Module/Plugin/DbStatusValidator.php(69): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#7 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#8 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'front-controlle...')
#9 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/module-page-cache/Model/App/FrontController/VarnishPlugin.php(55): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#10 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\PageCache\Model\App\FrontController\VarnishPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#11 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'front-controlle...')
#12 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php(68): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#13 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Interceptor.php(142): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#14 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/var/generation/Magento/Framework/App/FrontController/Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#15 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/App/Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#16 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
#17 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#18 {main}

解决方案

最后,我克服了这个问题,这是由于等前端di.xml <item name="sortOrder" xsi:type="string">20</item>中的排序.我将20更改为60,错误消失了. /p>

I am working on developing a module in magento2.The problem is with the routing-where the router return $this->actionFactory->create('Magento\Framework\App\Action\Forward'); does not redirect to my module,contorller and the action specified in the code;it thorws an exception Front controller reached 100 router match iterations.Any help would be highly appreciated.Thanks in advance!

public function match(\Magento\Framework\App\RequestInterface $request)
    {

 $identifier = trim($request->getPathInfo(), '/');

    $condition = new \Magento\Framework\DataObject(['identifier' =>   $identifier, 'continue' => true]);
    $this->eventManager->dispatch(
        'news_controller_router_match_before',
        ['router' => $this, 'condition' => $condition]
    );

    $identifier = $condition->getIdentifier();

    if ($condition->getRedirectUrl()) {

        $this->response->setRedirect($condition->getRedirectUrl());
        $request->setDispatched(true);
        return $this->actionFactory->create('Magento\Framework\App\Action\Redirect');
    }

    if (!$condition->getContinue()) {
        return null;
    }

    /*for main page */
    /*check identifier against news-configuration main page idendifier */

    //$mainIdentifier = $topic->getMainPageIdentifer();
     $mainIdentifier = 'news';

    if ($mainIdentifier == $identifier) {

        $request->setModuleName('news')->setControllerName('index')->setActionName('view');
         $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $identifier);
           return $this->actionFactory->create('Magento\Framework\App\Action\Forward');
    }



}
1 exception(s):
Exception #0 (LogicException): Front controller reached 100 router match iterations

Exception #0 (LogicException): Front controller reached 100 router match iterations
#0 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Interceptor.php(74): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#1 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Chain/Chain.php(70): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#2 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'requestPreproce...')
#3 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php(94): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#4 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#5 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'install')
#6 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Module/Plugin/DbStatusValidator.php(69): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#7 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#8 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'front-controlle...')
#9 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/module-page-cache/Model/App/FrontController/VarnishPlugin.php(55): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#10 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\PageCache\Model\App\FrontController\VarnishPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#11 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'front-controlle...')
#12 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php(68): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#13 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/Interception/Interceptor.php(142): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#14 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/var/generation/Magento/Framework/App/FrontController/Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#15 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/App/Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#16 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
#17 /opt/lampp/htdocs/Magento-CE-2.1.2_sample/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#18 {main}

解决方案

Finally I get over the issue, it was due to sortorder in etc frontend di.xml <item name="sortOrder" xsi:type="string">20</item> .I changed 20 to 60 and the error disappeared.

这篇关于Magento 2.1.2 Rourter动作工厂陷入无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 05:46