Token导航 LogoToken导航TokenDH.com
运维和基础设施需要联网github未标认证来源可访问clear审计通过

phoenix-controllersPhoenix controllers 命令行

Agent Skill

phoenix-controllers 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

682

周安装

29

GitHub Stars

142

下载量

239
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:phoenix-controllers(Phoenix controllers 命令行)
来源仓库:https://github.com/thebushidocollective/han
仓库路径:skills/phoenix-controllers
安装命令:
npx skills add https://github.com/thebushidocollective/han --skill phoenix-controllers
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/thebushidocollective/han --skill phoenix-controllers

简介

用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中围绕仓库状态或协作事项进行整理。
  • 通过 npx skills add 命令从指定仓库安装,需确认权限和维护状态。
  • 使用前建议核验是否会触发联网、命令执行或文件读写操作。
  • phoenix-controllers 属于运维和基础设施类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Phoenix Controllers

Phoenix controllers are the intermediary modules between the router and views in a Phoenix application. They handle HTTP requests, process parameters, interact with contexts, and determine what response to send back to the client. Controllers are stateless and receive a connection struct (conn) that represents the current HTTP request.

Basic Controller Structure

The simplest Phoenix controller uses the HelloWeb,:controller macro and defines actions as functions that receive the connection and parameters:

defmodule HelloWeb.PageController do
  use HelloWeb, :controller

  def home(conn, _params) do
    render(conn, :home, layout: false)
  end
end

Each controller action receives:

  • conn - The Plug.Conn struct representing the HTTP request/response
  • params - A map containing request parameters from the URL, query string, and request body

Controller Actions and Parameter Handling

Extracting Specific Parameters

Use pattern matching to extract specific parameters from the params map:

defmodule HelloWeb.HelloController do
  use HelloWeb, :controller

  def show(conn, %{"messenger" => messenger}) do
    render(conn, :show, messenger: messenger)
  end
end

Accessing Full Parameter Map

To access both a specific parameter and the full params map, use pattern matching with the = operator:

def show(conn, %{"messenger" => messenger} = params) do
  # Access to both messenger and the full params map
  render(conn, :show, messenger: messenger)
end

Ignoring Parameters

When an action doesn't need parameters, prefix the variable with an underscore to avoid compiler warnings:

def index(conn, _params) do
  render(conn, :home)
end

Renaming Actions

Action names can be customized independently of the template name:

defmodule HelloWeb.PageController do
  use HelloWeb, :controller

  def index(conn, _params) do
    # Renders :home template but action is named :index
    render(conn, :home)
  end
end

Update the router accordingly:

get "/", PageController, :index

Rendering Responses

Rendering HTML Templates

Use the render/3 function to render HTML templates via Phoenix Views:

defmodule HelloWeb.HelloController do
  use HelloWeb, :controller

  def show(conn, %{"messenger" => messenger}) do
    render(conn, :show, messenger: messenger)
  end
end

The controller and view must share a root name (e.g., HelloController and HelloHTML).

Rendering Without Layout

Disable the layout for specific actions:

def home(conn, _params) do
  render(conn, :home, layout: false)
end

Assigning Values to Templates

Using assign/3

Pass data to templates using assign/3:

def show(conn, %{"messenger" => messenger}) do
  conn
  |> assign(:messenger, messenger)
  |> render(:show)
end

Chaining Multiple Assigns

Chain multiple assigns for cleaner code:

def show(conn, %{"messenger" => messenger}) do
  conn
  |> assign(:messenger, messenger)
  |> assign(:receiver, "Dweezil")
  |> render(:show)
end

Passing Assigns Directly to render/3

For concise syntax, pass assigns directly to render/3:

def show(conn, %{"messenger" => messenger}) do
  render(conn, :show, messenger: messenger, receiver: "Dweezil")
end

Configuring Controller Formats

Configure supported response formats in your controller configuration:

def controller do
  quote do
    use Phoenix.Controller,
      formats: [:html, :json]
    ...
  end
end

This allows controllers to respond with different formats based on the request.

Flash Messages

Setting Flash Messages

Use put_flash/3 to set temporary messages:

defmodule HelloWeb.PageController do
  use HelloWeb, :controller

  def home(conn, _params) do
    conn
    |> put_flash(:error, "Let's pretend we have an error.")
    |> render(:home, layout: false)
  end
end

Flash message types:

  • :info - Informational messages
  • :error - Error messages
  • :warning - Warning messages (custom)
  • :success - Success messages (custom)

Clearing Flash Messages

Remove all flash messages from the connection:

clear_flash(conn)

Flash with Redirects

Combine flash messages with redirects to provide context after navigation:

def home(conn, _params) do
  conn
  |> put_flash(:error, "Let's pretend we have an error.")
  |> redirect(to: ~p"/redirect_test")
end

Redirects

Basic Redirect

Redirect to another route using the verified routes syntax:

def create(conn, params) do
  # ... create logic
  redirect(conn, to: ~p"/posts")
end

Redirect with Parameters

Include dynamic parameters in redirects:

def create(conn, params) do
  # ... create post
  redirect(conn, to: ~p"/posts/#{post}")
end

External Redirects

Redirect to external URLs:

def external(conn, _params) do
  redirect(conn, external: "https://example.com")
end

Action Fallback

Action fallback controllers handle error cases elegantly by centralizing error handling logic:

defmodule HelloWeb.MyController do
  use Phoenix.Controller

  action_fallback HelloWeb.MyFallbackController

  def show(conn, %{"id" => id}, current_user) do
    with {:ok, post} <- fetch_post(id),
         :ok <- authorize_user(current_user, :view, post) do
      render(conn, :show, post: post)
    end
  end
end

The fallback controller handles non-ok tuples:

defmodule HelloWeb.MyFallbackController do
  use Phoenix.Controller

  def call(conn, {:error, :not_found}) do
    conn
    |> put_status(:not_found)
    |> put_view(HelloWeb.ErrorHTML)
    |> render(:"404")
  end

  def call(conn, {:error, :unauthorized}) do
    conn
    |> put_status(403)
    |> put_view(HelloWeb.ErrorHTML)
    |> render(:"403")
  end
end

Testing Controllers

HTML Controller Tests

Test controller actions using ConnCase:

defmodule HelloWeb.PostControllerTest do
  use HelloWeb.ConnCase

  import Hello.BlogFixtures

  @create_attrs %{body: "some body", title: "some title"}
  @update_attrs %{body: "some updated body", title: "some updated title"}
  @invalid_attrs %{body: nil, title: nil}

  describe "index" do
    test "lists all posts", %{conn: conn} do
      conn = get(conn, ~p"/posts")
      assert html_response(conn, 200) =~ "Listing Posts"
    end
  end

  describe "show" do
    test "displays a single post", %{conn: conn} do
      post = post_fixture()
      conn = get(conn, ~p"/posts/#{post}")
      assert html_response(conn, 200) =~ post.title
    end
  end
end

Testing Redirects

Assert redirects in tests:

test "redirects after create", %{conn: conn} do
  conn = post(conn, ~p"/posts", post: @create_attrs)
  assert %{id: id} = redirected_params(conn)
  assert redirected_to(conn) == ~p"/posts/#{id}"
end

Testing Flash Messages

Verify flash messages are set correctly:

test "sets flash message on error", %{conn: conn} do
  conn = post(conn, ~p"/posts", post: @invalid_attrs)
  assert get_flash(conn, :error) == "Could not create post"
end

When to Use This Skill

Use this skill when you need to:

  1. Create new controller actions to handle HTTP requests
  2. Process and validate incoming request parameters
  3. Render HTML templates with dynamic data
  4. Implement user feedback with flash messages
  5. Handle redirects after form submissions or actions
  6. Test controller behavior and responses
  7. Implement error handling with action fallbacks
  8. Build RESTful API endpoints
  9. Integrate controller actions with Phoenix contexts
  10. Manage session data and user authentication flows
  11. Handle file uploads and multipart forms
  12. Implement pagination for list views
  13. Create custom response formats (JSON, XML, etc.)
  14. Debug request/response cycles

Best Practices

  1. Keep controllers thin - Move business logic to contexts, keep controllers focused on HTTP concerns
  2. Use pattern matching - Extract only the parameters you need from the params map
  3. Validate early - Validate parameters at the controller level before passing to contexts
  4. Use action fallback - Centralize error handling with action fallback controllers
  5. Leverage pipeline - Use plugs for common operations like authentication and authorization
  6. Be explicit with assigns - Pass only necessary data to templates to avoid exposing sensitive information
  7. Use verified routes - Always use ~p sigil for route paths to catch errors at compile time
  8. Test thoroughly - Write comprehensive tests for all controller actions and edge cases
  9. Handle errors gracefully - Provide meaningful error messages and appropriate HTTP status codes
  10. Use flash messages wisely - Provide clear, actionable feedback to users after actions
  11. Avoid business logic - Controllers should orchestrate, not implement business rules
  12. Return early - Use guard clauses and early returns for cleaner code
  13. Consistent naming - Follow Phoenix conventions for action names (index, show, new, create, edit, update, delete)
  14. Document complex actions - Add comments for non-obvious controller logic
  15. Use structs over maps - Work with structs from contexts rather than raw parameter maps when possible

Common Pitfalls

  1. Putting business logic in controllers - This makes code harder to test and reuse
  2. Not validating parameters - Always validate and sanitize user input
  3. Overusing assigns - Passing entire context modules or large data structures to views
  4. Ignoring error cases - Not handling errors from context functions properly
  5. Hard-coding paths - Using string paths instead of verified routes (~p)
  6. Not using action fallback - Repeating error handling logic across actions
  7. Testing implementation details - Test behavior, not internal implementation
  8. Exposing internal errors - Leaking stack traces or internal errors to users
  9. Not setting status codes - Forgetting to set appropriate HTTP status codes for errors
  10. Mutating params - Attempting to modify the params map instead of using assigns
  11. Skipping CSRF protection - Disabling security features without understanding implications
  12. Large controller files - Creating monolithic controllers instead of splitting concerns
  13. Not using with statements - Missing opportunities to chain operations cleanly
  14. Forgetting content negotiation - Not handling different response formats appropriately
  15. Mixing concerns - Handling both API and HTML responses in the same controller without proper separation

Resources

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

28.82%
按下载量换算69

Antigravity

22.65%
按下载量换算54

windsurf

19.66%
按下载量换算47

OpenCode

14.71%
按下载量换算35

Gemini CLI

7.87%
按下载量换算19

Codex

3.6%
按下载量换算9

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills