Skip to content

Elixir Phoenix Framework — Controllers, Views, LiveView and Routing

DodaTech Updated 2026-06-29 1 min read

In this tutorial, you will learn about Elixir Phoenix Framework. We cover key concepts, practical examples, and best practices to help you master this topic.

Phoenix is Elixir's web framework — fast, concurrent, and productive. Its LiveView feature enables real-time, server-rendered UIs without writing JavaScript.

In this tutorial, you'll learn Phoenix fundamentals for building web applications with Elixir.

Router

defmodule MyAppWeb.Router do
  use MyAppWeb, :router

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
  end

  scope "/", MyAppWeb do
    pipe_through :browser

    get "/", PageController, :home
    get "/users", UserController, :index
    get "/users/:id", UserController, :show
  end
end

Controller

defmodule MyAppWeb.UserController do
  use MyAppWeb, :controller

  def index(conn, _params) do
    users = MyApp.list_users()
    render(conn, :index, users: users)
  end

  def show(conn, %{"id" => id}) do
    user = MyApp.get_user!(id)
    render(conn, :show, user: user)
  end
end

LiveView

defmodule MyAppWeb.CounterLive do
  use MyAppWeb, :live_view

  def mount(_params, _session, socket) do
    {:ok, assign(socket, count: 0)}
  end

  def handle_event("inc", _, socket) do
    {:noreply, assign(socket, count: socket.assigns.count + 1)}
  end

  def render(assigns) do
    ~H"""
    <div>
      <h1>Count: <%= @count %></h1>
      <button phx-click="inc">+</button>
    </div>
    """
  end
end

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro