0

I'm trying to create a custom controller, but i have been having this error returned every time I try to run the module.

Uncaught Error: Call to undefined method Magento\Framework\App\Action\Action::construct()

Which is weird knowing that i've followed the exact process of creating controllers.

I've also tried looking for a similar case around the internet, but wasn't successful.

Here are the codes ive made so far:

=> module.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Jaycroll_Test" setup_version="2.2.0">
</module>

=> routes.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">

=> Write.php (the controller)

namespace Jaycroll\Test\Controller\Index;

use \Magento\Framework\App\Action\Action;

class Write extends Action
{
  public function __construct( \Magento\Framework\App\Action\Context $context ) {
     return parent::construct( $context );
  }
  public function execute()
  {
        var_dump("test");
        die('test index');
  }
}

Currently running Magento 2.2 on developer mode. I can't simply run setup:di:compile as i need to modify the module from time to time (https://www.cadence-labs.com/2017/07/magento-2-run-setupdicompile/)

2 Answers 2

0

It is not parent::construct.

It should be parent::__construct

You missed to add the prefix: __.

1
  • Do'h. there we go. You're right. I shouldve checked the method name it self. (will accept the answer in a few minutes. looks like SO puts a timer on the accept button)
    – jaycroll
    Commented Oct 16, 2017 at 1:26
0
//check your namespace path Write.php file should be inside Jaycroll\Test\Controller\Index folder
namespace Jaycroll\Test\Controller\Index;

use \Magento\Framework\App\Action\Action;

class Write extends Action
{
  public function __construct( \Magento\Framework\App\Action\Context $context ) 
       //use this 
    return parent::__construct( $context );
    //instead of 
     //return parent::construct( $context );


  }
  public function execute()
  {
        var_dump("test");
        die('test index');
  }
} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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