new feature

2 views
Skip to first unread message

Yariv Sadan

unread,
Aug 19, 2007, 12:49:58 AM8/19/07
to erl...@googlegroups.com
Hi,

Following up on the 'metafunctions' thread, I added a feature in
ErlyWeb letting controllers implement a 'catch_all/3' function that is
called when clients request a controller function that doesn't exist.

Here's an example of how to use it:

foo_controller:

-module(foo_controller).
-compile(export_all).

catch_all(A, FuncName, Params) ->
{data, {A, FuncName, Params}}.

in foo_view.et:

<%@ catch_all(Data) %>
<% io_lib:fwrite("~p", [Data]) %>

Then, request

http://localhost:8080/foo/bar/1/2/3

This will cause catch_all to be called with FuncName "foo" and Params
["1", "2", "3"].

Note: 'catch_all' is now a reserved function name. E.g. when a user
requests http://localhost:8080/foo/catch_all/1/2/3, ErlyWeb won't let
the user access it directly. Instead, ErlyWeb will tread this function
as non-existing, and call catch_all(A, "catch_all", ["1", "2", "3"]).

Let me know if you find any problems.

Thanks,
Yariv

Yariv Sadan

unread,
Aug 19, 2007, 12:50:44 AM8/19/07
to erl...@googlegroups.com
Btw, erlyweb_util:indexify is now deprecated in favor of catch_all.

Yariv Sadan

unread,
Aug 19, 2007, 2:42:35 AM8/19/07
to erl...@googlegroups.com
Update:

I changed the catch_all/3 function so it takes two parameters: A and
Params. So, if the user requests http://host/foo/bar/1/2/3, and the
function 'bar/4' doesn't exist in 'foo_controller', ErlyWeb would call
'foo_controller:catch_all(A, ["bar", "1", "2", "3"]). This makes
catch_all a more natural replacement to erlyweb_util:indexify().

Yariv

On 8/18/07, Yariv Sadan <yariv...@gmail.com> wrote:

Reply all
Reply to author
Forward
0 new messages