0

My controller working but getFullActionName() not called

My controller path: Magento20/app/code/Test/Module1/Controller/Index/Index

<?php 
namespace Test\Module1\Controller\Index; 

class Index extends \Magento\Framework\App\Action\Action {

    protected $resultPageFactory;

  public function __construct(
    \Magento\Framework\App\Action\Context $context,
    \Magento\Framework\App\Request\Http $request,
   \Magento\Framework\View\Result\PageFactory $resultPageFactory)     
    {
   parent::__construct($context);
   echo  $request->getFullActionName(); // THIS CODE IS NOT WORK
   die();
        $this->resultPageFactory = $resultPageFactory;


    }

    public function execute()
    {
        $resultPage = $this->resultPageFactory->create();
        $resultPage->getConfig()->getTitle()->prepend(__('test example'));
        return $resultPage;
    }
}
 ?>

Edit
error is

a:4:{i:0;s:446:"Recoverable Error: Argument 2 passed to Test\Module1\Controller\Index\Index::__construct() must be an instance of Magento\Framework\App\Request\Http, instance of Magento\Framework\View\Result\PageFactory given, called in C:\xampp\htdocs\magento20\var\generation\Test\Module1\Controller\Index\Index\Interceptor.php on line 14 and defined in C:\xampp\htdocs\magento20\app\code\Test\Module1\Controller\Index\Index.php on line 11";i:1;s:7015:"#0 C:\xampp\htdocs\magento20\app\code\Test\Module1\Controller\Index\Index.php(11): Magento\Framework\App\ErrorHandler->handler(4096, 'Argument 2 pass...', 'C:\\xampp\\htdocs...', 11, Array)
#1 C:\xampp\htdocs\magento20\var\generation\Test\Module1\Controller\Index\Index\Interceptor.php(14): Test\Module1\Controller\Index\Index->__construct(Object(Magento\Framework\App\Action\Context), Object(Magento\Framework\View\Result\PageFactory))
#2 C:\xampp\htdocs\magento20\vendor\magento\framework\ObjectManager\Factory\AbstractFactory.php(99): Test\Module1\Controller\Index\Index\Interceptor->__construct(Object(Magento\Framework\App\Action\Context), Object(Magento\Framework\View\Result\PageFactory))
#3 C:\xampp\htdocs\magento20\vendor\magento\framework\ObjectManager\Factory\Dynamic\Developer.php(89): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('Test\\Marketp...', Array)
#4 C:\xampp\htdocs\magento20\vendor\magento\framework\ObjectManager\ObjectManager.php(57): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create('Test\\Marketp...', Array)
#5 C:\xampp\htdocs\magento20\vendor\magento\framework\App\ActionFactory.php(37): Magento\Framework\ObjectManager\ObjectManager->create('Test\\Marketp...')
#6 C:\xampp\htdocs\magento20\vendor\magento\framework\App\Router\Base.php(300): Magento\Framework\App\ActionFactory->create('Test\\Marketp...')
#7 C:\xampp\htdocs\magento20\vendor\magento\framework\App\Router\Base.php(161): Magento\Framework\App\Router\Base->matchAction(Object(Magento\Framework\App\Request\Http), Array)
#8 C:\xampp\htdocs\magento20\vendor\magento\framework\App\FrontController.php(50): Magento\Framework\App\Router\Base->match(Object(Magento\Framework\App\Request\Http))
#9 [internal function]: Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#10 C:\xampp\htdocs\magento20\vendor\magento\framework\Interception\Interceptor.php(74): call_user_func_array(Array, Array)
#11 C:\xampp\htdocs\magento20\vendor\magento\framework\Interception\Chain\Chain.php(70): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#12 C:\xampp\htdocs\magento20\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...')
#13 C:\xampp\htdocs\magento20\vendor\magento\module-store\App\FrontController\Plugin\RequestPreprocessor.php(89): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#14 [internal function]: Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#15 C:\xampp\htdocs\magento20\vendor\magento\framework\Interception\Chain\Chain.php(68): call_user_func_array(Array, Array)
#16 C:\xampp\htdocs\magento20\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')
#17 C:\xampp\htdocs\magento20\vendor\magento\framework\Module\Plugin\DbStatusValidator.php(69): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#18 [internal function]: Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#19 C:\xampp\htdocs\magento20\vendor\magento\framework\Interception\Chain\Chain.php(68): call_user_func_array(Array, Array)
#20 C:\xampp\htdocs\magento20\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'storeCookieVali...')
#21 C:\xampp\htdocs\magento20\vendor\magento\module-store\Model\Plugin\StoreCookie.php(78): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#22 [internal function]: Magento\Store\Model\Plugin\StoreCookie->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#23 C:\xampp\htdocs\magento20\vendor\magento\framework\Interception\Chain\Chain.php(68): call_user_func_array(Array, Array)
#24 C:\xampp\htdocs\magento20\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...')
#25 C:\xampp\htdocs\magento20\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))
#26 [internal function]: Magento\PageCache\Model\App\FrontController\VarnishPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#27 C:\xampp\htdocs\magento20\vendor\magento\framework\Interception\Chain\Chain.php(68): call_user_func_array(Array, Array)
#28 C:\xampp\htdocs\magento20\vendor\magento\framework\Interception\Interceptor.php(136): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'front-controlle...')
#29 C:\xampp\htdocs\magento20\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))
#30 [internal function]: Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#31 C:\xampp\htdocs\magento20\vendor\magento\framework\Interception\Interceptor.php(141): call_user_func_array(Array, Array)
#32 C:\xampp\htdocs\magento20\var\generation\Magento\Framework\App\FrontController\Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#33 C:\xampp\htdocs\magento20\vendor\magento\framework\App\Http.php(115): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#34 C:\xampp\htdocs\magento20\vendor\magento\framework\App\Bootstrap.php(258): Magento\Framework\App\Http->launch()
#35 C:\xampp\htdocs\magento20\index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#36 {main}";s:3:"url";s:34:"/magento20/Module1/index/index";s:11:"script_name";s:20:"/magento20/index.php";}
2
  • delete var/generation folder
    – Sohel Rana
    Jan 6, 2016 at 8:47
  • Wow greate answer bro thanks sohel rana,thank you very much...thanks thanks thanks Jan 6, 2016 at 8:51

3 Answers 3

3

You can not call this function from __construct function

Please try:

Note: delete var/generation folder after follow below code

<?php 
namespace Test\Module1\Controller\Index; 

class Index extends \Magento\Framework\App\Action\Action {

    protected $resultPageFactory;
    protected $request;

  public function __construct(
    \Magento\Framework\App\Action\Context $context,
    \Magento\Framework\App\Request\Http $request,
   \Magento\Framework\View\Result\PageFactory $resultPageFactory)     
    {

        $this->resultPageFactory = $resultPageFactory;
        $this->request = $request;

        parent::__construct($context);
    }

    public function execute()
    {
        $fullActionName= $this->request->getFullActionName(); 
        $resultPage = $this->resultPageFactory->create();
        $resultPage->getConfig()->getTitle()->prepend(__($fullActionName.'test example'));
        return $resultPage;
    }
}
 ?>
1
  • Thank you very much for help and just I have edited your answer and add first line delete var/generation folder Jan 6, 2016 at 8:58
0
public function process(\Magento\Framework\App\RequestInterface $request) {
    if($request->getControllerName() == 'product' && $request->getModuleName() == 'catalog'){
        $request->setModuleName('cms')->setControllerName('page')->setActionName('view')->setParam('page_id', 8);
    }else if($request->getControllerName() == 'category' && $request->getModuleName() == 'catalog'){
        $request->setModuleName('cms')->setControllerName('page')->setActionName('view')->setParam('page_id', 7);
    }else{
        $request->setModuleName('cms')->setControllerName('index')->setActionName('index'); 
    }
}

You just add Request interface \Magento\Framework\App\RequestInterface $request

0

Just try with this code:

put parent::__construct($context);

above ur code

$request->getFullActionName();

You will get,ur result

1
  • Not work I have edited my question and throw error in edit section Jan 6, 2016 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.