Skip to content

UrlBuilders and Helpers

jetviper21 edited this page Sep 13, 2010 · 6 revisions

Url Format support

Any route can have multiple formats that you can respond differently to. This functionality is very similar to ruby on rails.

default is “html”

This is best show by Example:

class MyController extends Controller {

  public function show($id) {
    $this->photos = get_photos();


  switch($this->format) {
      case 'html':
        $this->render('views/index.php');
      break;
      case 'xml':
        echo $this->photos->to_xml();
      break;
    }
  }
}

Global Methods
This syntax may change some.

url_for($controller, $action, $params)

$controller = name of the controller
$action = name of the action you want to navigate to.
$params = an array of parameter that is in the same order as they are shown in the url ex. /user/:user_id/note/:id would be array(1,2)
Example:

url_for(“Form”, “show”, 1);

Command line tools

There is a command line tool for listing out all the routes you have created in your application
it can be invoked as follows

  • note ‘niceroutes’ is in the nimble bin directory *

    php niceroutes