I want to write a controller to insert data into the database using MySQL. What are the steps I need to follow to create it?


1 Answer 1


Magento 2 isn't exactly A MVC system, so you'll not use the Controller to "play" with the data. This is the role of a Block.

The Block will be called by the layout xml (which is called by the controller execute method, depending on the route name).

Then inside your block, you'll be able to interact with the model layer in order to insert data.

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.