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 Answer 1

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 !!

5
  • 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
    Commented Nov 6, 2019 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. Commented Nov 6, 2019 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. Commented Nov 6, 2019 at 7:16
  • 1
    Ok, after deleting the Modules folder in generated/code it works. Thank you
    – Black
    Commented Nov 6, 2019 at 7:23
  • welcome. Happy Coding !! :) Commented Nov 6, 2019 at 7:24

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.