Let's say I have a site which hots multiple documents. I'd like to
access them like this:
http://site/document_name
I sort of figured it out for ErlyWeb by looking at (rather old) Twoorl
code:
hook(A) ->
A1 = normalize_appmoddata(A),
case erlyweb:get_initial_ewc({ewc, A1}) of
{page, "/"} -> start(A1);
% Make sure static data id ok
{page, "/static" ++ _Static} = Ewc -> Ewc;
{page, "/favicon.ico"} = Ewc2 -> Ewc2;
% Get the doc name and fire away
{page, PageName} -> {ewc, page, show, [A1, PageName]};
_Ewc -> start(A1)
end.
%% start function is unmodified
start(A) ->
{A2, LoggedIn} = auth(A),
Appmod = yaws_arg:appmoddata(A2),
case Appmod of
"/api" ++ _ ->
{ewc, A2};
"/" when LoggedIn == true ->
{ewr, home};
_ ->
Appmod1 = case Appmod of
"/" ->
"/main";
_ ->
Appmod
end,
A3 = yaws_arg:appmoddata(A2, Appmod1),
{phased, {ewc, A3},
fun(_Ewc, Data, PhasedVars) ->
{ewc, html_container,
[A3,
{ewc, layout, [A3, {data, Data}]},
PhasedVars]}
end}
end.
In my page controller I have
show(A, L) ->
{data, {ok, Page}}.
As ErlyWeb gurus have already noticed is that I get an unparsed string
in my PageName:
http://site/hello/ %% PageName = "/hello/"
http://site/hello/there/ %%PageName = "/hello/there/"
What I'd *really* want to have is a way to be able to sort of "inject"
the controller and the function into the equation :) So that ErlyWeb
would still parse the arguments...
If I modify the start function as follows
Appmod1 = case Appmod of
"/" ->
"/main";
_ ->
"/page/show/" ++ Appmod
end,
then returning ewr from the page controller throws up an error:
http://site/hello/
ERROR erlang code crashed:
File: appmod:0
Reason: {badarg,[{lists,split,[-11,"/hello/"]},
{erlyweb,get_app_root,1},
{erlyweb,ewr2,2},
{erlyweb,is_redirect,2},
{erlyweb,ewc,2},
{erlyweb,handle_request,6},
{yaws_server,deliver_dyn_part,8},
{yaws_server,aloop,3}]}
Req: {http_request,'GET',{abs_path,"/hello/"},{1,1}}
I'm at loss :) Whatever shall i do? :)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"erlyweb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---