Creating a controller
In Phoenix, controllers are Elixir modules that define functions (or actions) to handle the requests dispatched by the router. The controllers are responsible for preparing and passing data to the view layer and determining the rendering of these views.
Getting ready
To get started, we will extend the project defined in the Defining routes recipe. The defined routes are as follows:
page_path GET / Todo.PageController.index/2 my_path GET /text Todo.MyController.plaintext/2 my_path GET /generated Todo.MyController.send_html/2 todos_path GET /todos Todo.TodosController.index/2 todos_path GET /todos/:id/edit Todo.TodosController.edit/2 todos_path GET /todos/new Todo.TodosController.new/2 todos_path GET /todos/:id Todo.TodosController.show/2 todos_path POST /todos Todo.TodosController.create/2 todos_path PATCH /todos/:id Todo.TodosController.update/2 ...