我需要从phoenix频道调用控制器内的一个函数。这是我的凤凰频道
//dashboardChannel.ex
def join("dashboard:lobby", payload, socket) do
IO.puts "Entered Room"
if authorized?(payload) do
{:ok, socket}
else
{:error, %{reason: "unauthorized"}}
end
end
这是我的handle_in函数
//dashboardChannel.ex
def handle_in("new_msg", %{"uid" => uid, "body" => body}, socket) do
broadcast_from! socket, "new_msg", %{uid: uid, body: body}
MyApp.Endpoint.broadcast_from! self(), "dashboard:lobby", "new_msg", %{uid: uid, body: body}
{:noreply, socket}
end
以下是我的控制器功能,此控制器的路线为" / users"
//dashboardController.ex
def index(conn, _params) do
IO.puts "Enters Users Controller"
MyApp.Endpoint.broadcast_from! self(), "dashboard:lobby", "new_msg", %{"uid" => "ac4452s", "body" => "Sample User"}
IO.puts "Must have executed User Controller"
users = Accounts.list_users() // It will list all my users
render(conn, "index.json", users: users)
end
我是凤凰和长生不老的新手。我需要从上面的凤凰频道调用" / users" 控制器功能。我怎么称呼那个。有没有办法从凤凰频道调用控制器功能,并调用handle_in函数,即#34; new_msg"从控制器方法。提前致谢
以下是我的要求