0

I created a new controller action called "AddEmailToCustomerModel"

But I got an exception after trying to call the route:

Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Fekete\Newsletter2Go\Controller\Index\AddEmailToCustomerModel\Interceptor

So I removed the name Model from the action name and its filename, and it works now!

Why does it not work if there is Model in the name?

And are there more reserved words we should know about?

1

It's working fine with AddEmailToCustomerModel with this action name. This type of error generate when :

1) You inject any class in construct and forgot to remove generated folder. Because, the interceptor file needs to be re-created or refresh.

2) If you forget to inject \Magento\Framework\App\Action\Context $context class in your controller construct and call parent construct.

Hope, it's easy to understand !!

  • Im not sure what you mean with 1) do I have to delete a folder everytime when I inject a class in a construct? And to 2), no I did not forgot it, I also call parent construct. Simply renaming the class and its file, solved the problem for me. So my conclusion is, that "Model" is reserved and not allowed in class Names. – Black Nov 6 '19 at 7:12
  • In which module's construct you will. You can also remove that module's folder from generated folder. You can find your module in generated/code folder. – Rohan Hapani Nov 6 '19 at 7:14
  • I checked with AddEmailToCustomerModel.php action file name and it's working properly. So, maybe you forgot to remove generated folder after inject class in construct. Please try again and let me know if still not working. – Rohan Hapani Nov 6 '19 at 7:16
  • 1
    Ok, after deleting the Modules folder in generated/code it works. Thank you – Black Nov 6 '19 at 7:23
  • welcome. Happy Coding !! :) – Rohan Hapani Nov 6 '19 at 7:24

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.