class World extends \Magento\Framework\App\Action\Action
    protected $logger;
    public function __construct(Context $context, \Psr\Log\LoggerInterface $logger)
         $this->logger = $logger;
        return parent::__construct($context);
     public function execute()

In Magento 1 the controller action executes always when we go to the corresponding url. But in magento 2 "Test" gets logged only when i clear my cache and go to the controller url otherwise it doesn't. How can i add it to a controller in magento 2 so that it will keep on executing the code when i go to the corresponding url, without clearing the cache, like magento 1.

  • i faced same issue here.can u tell me what is the solution.i override catalog product view controller – Sivakumar K Jul 23 '16 at 12:10
  • I'm really sorry i also couldn't figure out the exact issue. I created a new controller and it started working fine. – Lakshin Karunaratne Jul 23 '16 at 17:17

Change your code by


  • Tried. Still it only prints if i clear my cache. Seems like the execute method gets executed if the cache is cleared. – Lakshin Karunaratne Jul 9 '16 at 17:54
  • which version you tried? It's work with M2.10, M2.0.5 – Sohel Rana Jul 9 '16 at 18:29
  • I tried with Magento community edition 2.1. I think it's happening because of the magento full page cache. – Lakshin Karunaratne Jul 10 '16 at 4:51
  • May be, But I tested enable/disable cache both. – Sohel Rana Jul 10 '16 at 6:01
  • I created another controller and tried and it started working. The previous controller was returning $this->pageFactory->create(). Don't know why it didn't work. – Lakshin Karunaratne Jul 10 '16 at 8:58

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.