Re: [Cppcms-users] url mapper
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2012-03-07 15:25:44
|
>> It was just an example >> >> However, if you call <% render ... %> from the view it renders to the >> output stream without intermediate buffers. > > My plugin has a print(ostream& ) function and the print() is wrapped in a > cppcms::filters::streamable main which is printed by <%= main | raw %>. > There should also be no intermediate buffer, or? > Yep >> I think you had not added m_form.x to m_form (using m_form.add(x)); >> so when you access x.value() it appears not to be loaded when you >> call load(app.context()); > > You are completely right! > Thanks a lot! > I suggest to change the text "Value was not loaded" to something like > "The > value or the parent was not loaded. Check the hierarchy." ;) > Ok... It may not always be the case but I'll take a look on i. >>> Is there some explanation how this works if multiple applications are >>> mounted at the same root? >> >> The behavior is undefined for `cppcms::application_pool` > > Mmmh, but exactly this happens when you use the file server? > It is also mounted at "". > Note, CppCMS HTTP server requires a set of script names that are valid. The invalid script name would be "" - i.e. the script name that could not be found and internal file server is mounted to it. It still uniquely defines it. So do not relay on this behavior, create mutually exclusive mount points. And for most of cases it is better to have one hierarchy and mount entirly different applications to different mount points. I mean if you add a new application it is better to add it as sub-application to the hierarchy then add it to the new mount point. > >>>> Because when you map sub-application and refer to it >>>> you automatically referred to the default URL >>>> of the sub-application - empty one "empty key" >>> >>> Sorry, I do not understand this statement. >>> > > How does the <% url ... %> using syntax work? > > Why does <% url "/blog/post" using slug %> resolves to > "/myblog/Hi%20%3cyou%3e/" > (see http://cppcms.com/wikipp/en/page/cppcms_1x_templates_comm#URL.Mapping) > > I would rather expect /blog/post/Hi%20%3cyou%3e/? > See, it is YOUR urls design, it is rendered the way you define it. You do not have to name applications and URLs the same way (of course it is good idea to be consistent) Remember there is: URL format and Application Hierarchy they do not have to be the same. > Both > <% url "/gui/system" %> > <% url "system" %> > work without problem, but I could not figure out how to resolve a variable > containing "system"? > > E.g. <% url "/gui/" using menu_element.m_href %> does not work? > What do you mean? > >> when you call url("foo") it looks for the object named > "foo" >> >> If it is actual function (not sub application) it provides a url >> >> if it is subapplication it tries to dispatch the "" key. > > Ok, I think I understand the approach now much better. > > I still can't figure out the details between: > url("") > url(".") > url("/") > > while the first two seem to be equivalent, url("/") seems to link to > the > same url where the request() came from? No "/" - means default URL of the topmost application - root, the "." and "" refer to CURRENT application, i.e. the application that calls url() or render() that uses <% url ... %> If the path does not begin with "/" then relative URLs are sed. > e.g. when I request http://localhost:10000/gui/wrong_url > url("/") resolves to http://localhost:10000/gui/wrong_url > but url("") and url(".") resolves to > http://localhost:10000/gui > > When I use > dispatcher().assign("", &GUI::show_error_page, this); > mapper().assign("/"); // changed here instead of "" > See you are not consistent > dispatcher().assign("", &GUI::show_error_page, this); This would map show_error_page to some empty ending. > mapper().assign("/"); // changed here instead of "" Would create "/" as ending != "", In your case if the "show_error_page" is the default URL for the application then you should call mapper().assign(""); > the urls resolve to: > url("/") -> http://localhost:10000/gui/wrong_url > url(".") -> http://localhost:10000/gui/ > url("") -> http://localhost:10000/gui/ > Because "/" does not go to GUI but rather GUI's parent (topmost) > > Thanks, I think I do not need parameters, because I prefer to have > user/browser specific language and not by url. > Parameters rather define some named resource like /post/124 then the formatting would be "/post/{1}" and you would call url("post,124); >> Actually, wikipp was written before URL-mapper existed and I had >> no time to update it. Take a look rather on the cppcms's blog >> it uses url mapper fully. > > Ok, so I think the examples you gave in this mail are perfect! > Not sure so how to make it even more clear, because I assume more question will come. Artyom |