GnomePHP, New Router

Posted on 26th October 2011, 12:00 AM

GnomePHP just got better! We have introduced the new Router library for our framework. The router configuration setup is inspiered by Play! Framework.

Ease of use and much better intelligence when reversing uri routes is the key of the new library.

Example of the new routing config:

# Default main route
*  /  Main.index()
GET  /news/{id}  News.show($id)
# Regexp validation if wanted between <> brackets!
POST		/news/{<\d+>id}				News.postNews($id)

# /show/test will run controller ShowMethods and method "method": ShowMethods->method()
# Do you see the /? it will pass all the next arguments to the method.
# Meaning we also accept /show/test/1/2/test/3
*  /show/{method}/?  ShowMethods.$method()

# Extend existing functionality?
{extend=core/captcha}

# Default routing /controller/method
*  /{controller}/{method}  $controller.$method()


Doesn't that just look beautiful?

Even better, creating links in the views is really simple!

# Will give out link to the main page (eg. mypage.com/ )
echo $view->url->linkTo('Main', index);

A big milestone for us today, cleaning the important bit of the routing and flexibility is huge.

Go to gnomephp.org to download the latest version of GnomePHP.


Leave a reply

Please write the code you see on this image:

Human verification