Catalog / Phoenix Framework Cheatsheet
Phoenix Framework Cheatsheet
A comprehensive cheat sheet covering essential Phoenix framework commands, directory structure, routing, Ecto interactions, and more, with examples.
Getting Started
Installation
Ensure you have Erlang, Elixir, Node.js, and PostgreSQL installed.
|
Project Creation
Create a new Phoenix project:
|
This generates a basic Phoenix application. Follow the instructions to set up the database and start the server. |
Directory Structure
Key Directories
|
Compiled Elixir code. |
|
CSS, JavaScript, and static files. |
|
Application configuration files. |
|
Project dependencies. |
|
Source code for the application, including contexts, schemas, and web-related files. |
|
Database migrations and static assets. |
|
Tests for the application. |
Routing
Basic Routing
Define routes in
|
Resource Routing
Generate routes for a resource:
|
Path Helpers
Use path helpers to generate URLs:
|
Controllers and Conn
Accessing Request Data
Access request data through the
|
Modifying the Conn
Use
|
Ecto Migrations
Generating Migrations
Generate a migration file:
|
Migration Example
Example migration:
|
Generating HTML
Generating HTML Resources
Generate HTML resources using
|
Replace |