Unable to get default working with haxe.Web.Dispatch -


i setting website using haxe targetting php , i'm having problem haxe.web.dispatch library.

everything working until tried implement dodefault() rule.

i have following rules in dispatch api:

doindex(){ ... }  doposts(){y:string, m:string, n:string){ ... } 

and these both redirect correct webpage. example these both work fine:

http://foo.com/index http://foo.com/posts/2013/01/post-title 

and i've implemented

dodefault() {...} 

in order redirect other urls 404 page, it's not working. going above urls still works fine going to

http://foo.com/bar 

gives following error

uncaught exception: detoomanyvalues  in file: c:\wamp\www\website\bin\lib\haxe\web\dispatch.class.php line 191 #0 c:\wamp\www\website\bin\lib\index.class.php(9): haxe_web_dispatch->runtimedispatch(object(_hx_anonymous)) #1 c:\wamp\www\website\bin\lib\index.class.php(12): index->__construct() #2 c:\wamp\www\website\bin\index.php(9): index::main() #3 {main} 

the dispatch documentation says

in case corresponding method doxxxx not found on api object, or if url /, action dodefault used instead. exception dispatcherror.denotfound("xxxx") thrown if there no default action (xxxx here being placeholder url part name).

but doesn't detoomanyvalues exception. have ideas?

the detoomanyvalues error thrown if url dispatching has more parts matching action.

so if have:

dopage( name:string ); 

then default "/page/aboutus/" work, "/page/aboutus/2/" not. applies dodefault() - "/" work, "/bar" not (by default).

the trick getting work using "dispatch" argument.

dopage( name:string, d:haxe.web.dispatch ) {     trace('get page $name, other parts: ${d.parts}'); } dodefault( d:haxe.web.dispatch ) {     trace('get page $name, other parts: ${d.parts}'); } 

if dispatch knows action/method has dispatch argument, assumes method knows how deal values, , no longer throw error. can use d.parts array access parts.

added bonus:

you can use d:disaptch argument to:

// redirect different page, same get/post parameters d.redirect("/differentpage/", d.params);   // redirect different controller.  if in /dodefault/, whole url passed sub-controller.   // if in `dopage` , url /page/some/other/part, `/some/other/part` passed on. d.dispatch(new someothercontroller());  

i have blog post explains more stuff if you're interested:

http://jasononeil.com.au/2013/05/29/creating-complex-url-routing-schemes-with-haxe-web-dispatch/

also feel free keep asking questions, keen else using haxe websites :)


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -