Erlang/OTP Forums

Author Message

<  Erlyweb mailing list  ~  new feature

Guest
Posted: Sun Aug 19, 2007 4:50 am Reply with quote
Guest
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

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Sun Aug 19, 2007 4:51 am Reply with quote
Guest
Btw, erlyweb_util:indexify is now deprecated in favor of catch_all.

On 8/18/07, Yariv Sadan <yarivsadan@gmail.com> wrote:
> 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
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Sun Aug 19, 2007 6:42 am Reply with quote
Guest
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 <yarivsadan@gmail.com> wrote:
> 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
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum