In the Phoenix code below where is the render() function being referenced from? Where is its actual declaration?
defmodule AppxWeb.HelloController do
use AppxWeb, :controller
def world(conn, _params) do
render(conn, "world.html")
end
end
In the Phoenix code below where is the render() function being referenced from? Where is its actual declaration?
defmodule AppxWeb.HelloController do
use AppxWeb, :controller
def world(conn, _params) do
render(conn, "world.html")
end
end
It is in the Phoenix controller code…
To supplement more details…
use AppxWeb, :controller
calls the AppxWeb.controller/0
function via AppxWeb.__using__/1
macro.AppxWeb.controller/0
imports Phoenix.Controller
.Before using Phoenix, learning some basic Elixir is important.
I’m not 100% sure but afaik there’s no “magic” in Phoenix/Elixir, I mean there is no implicit “code injection”.
So the only place where any function that you are using without a Module name (like render
here) could only reside in that module itself (in def
or defp
) or in any module you are explicitly import
ing or use
ing. The only exception being functions from the Kernel
module where they are imported automatically.
Even alias
ing modules still need to call functions with the aliased module name…
I think that this can help better understand how things are tied together in Elixir projects.
The explicitness of Elixir make it very clear. Also this reminds me a recent discussion here in the forum about implicitness vs explicitness… (will update with the link, currently on mobile)