Quick Start
Learn core Phoenix concepts and web development patterns. This Quick Start teaches essential Phoenix skills.
🎯 What You’ll Learn
By the end of this tutorial, you’ll understand:
- Routing and controllers
- Templates and views
- Contexts and schemas
- LiveView for real-time features
📋 Prerequisites
- Phoenix installed (see Initial Setup)
🛣️ Routing and Controllers
Edit lib/myapp_web/router.ex:
scope "/", MyAppWeb do
pipe_through :browser
get "/", PageController, :index
get "/about", PageController, :about
resources "/posts", PostController
endCreate controller lib/myapp_web/controllers/page_controller.ex:
defmodule MyAppWeb.PageController do
use MyAppWeb, :controller
def index(conn, _params) do
render(conn, :index)
end
def about(conn, _params) do
render(conn, :about)
end
end📄 Templates and Views
Create lib/myapp_web/controllers/page_html/about.html.heex:
<h1>About Us</h1>
<p>Welcome to our Phoenix application!</p>📊 Contexts and Schemas
Generate a context:
mix phx.gen.html Blog Post posts title:string body:textThis creates:
- Context:
lib/myapp/blog.ex - Schema:
lib/myapp/blog/post.ex - Controller, views, templates
Add to router:
resources "/posts", PostControllerRun migrations:
mix ecto.migrate⚡ LiveView
Generate LiveView:
mix phx.gen.live Counter Count counts value:integerAdd to router:
live "/counter", CountLive.Index, :index✅ Next Steps
You now understand Phoenix essentials!
- Try the examples: Build routes, controllers, and LiveViews
- Explore By Example: Elixir Phoenix By Example
🎯 Self-Assessment
After completing this Quick Start, you should be able to:
- Define routes and controllers
- Create templates and views
- Use contexts and schemas
- Build LiveView components
Last updated