Skip to content
jimmysparkle edited this page Aug 18, 2010 · 1 revision

Powerful URI parsing with interchangeable URI parsers means your URLs can be search engine friendly, yet sophisticated and flexible.

Introduction & Features

URI parsing is done by atsumi which maps a URI down to your projects controller & method as specified in the projects specification in the settings file. The URI parsers are interchangeable, the default URI parser is Gyokuro. Each URI parser is individual and it’s easy to write your own if you want your URI to be structured a specific way.

Gyokuro Parser

The Gyokuro is the default URI parser in Atsumi. Below is an example specification. Below the specification is a table of example URI’s showing how the gyokuro parser would map to the example specification.

Example Speicifcation

public function init_specification () {
	return	array(	
		""		=> "example_FrontPageController",
		"news"		=> "example_NewsController",
		"shop"	=> array (
			""		=> "example_ShopController",
			"catalogue" 	=> array (
				""			=> "example_CatalogueController",
				"product" 		=> "example_ProductController",
			),
			"checkout" 	=> "example_CheckoutController"
		)
	);	
}

Example URI’s and parse data

no. URI Controller Method Args
1 / example_FrontPageController page_index
2 /about_us/ example_FrontPageController page_about_us
3 /contact/ example_FrontPageController page_contact
4 /contact/_technical/ example_FrontPageController page_contact ‘technical’
5 /news/ example_NewsController page_index
6 /news/latest/ example_NewsController page_latest
7 /news/latest/_4/ example_NewsController page_latest 4
8 /news/article__new-products/ example_NewsController page_article ‘new-products’
9 /news/article__new-products/edit/ example_NewsController page_edit
10 /shop/ example_ShopController page_index
11 /shop/catalogue/__footwear/ example_CatalogueController page_index ‘footwear’
12 /shop/catalogue/__footwear/_2/ example_CatalogueController page_index ‘footwear’, 2
13 /shop/catalogue/__footwear/product__19/ example_ProductController page_index 19

Referencing an earlier segment of the URI

This is really powerful stuff it allows you to collect the data from an earlier part of the URI. The easiest way to explain is via an example:

class example_CatalogueController extends mvc_AbstractController {
	public function data_index ($catalogueCode) {
		return example_CatalogueModel::loadFromCode($this->app->init_db, $catalogueCode);
	}
	public function page_index ($catalogueCode) {
		/* get the catalogue object */
		$catalogue = $this->getData();
	}
}
class example_ProductController extends mvc_AbstractController {
	public function page_index ($productId) {
		/* get the catalogue object */
		$catalogue = $this->getData('catalogue', 'example_CatalogueController');
	}
}

Above shows the example_CatalogueController and example_ProductController classes. Notice how the in the Catalogue controller the page_index (would be called in URI parser examples table row #11 ) also has a data_index, data_index can be used to return the data object the controller method uses. This means it can be referenced further along the URI such as in the example_ProductController page_index (would be called in URI parser examples table row #13 ).

Other features

methodlessRequest ($request);

The methodless request gets called if the expected method doesn’t exist. Every controller can have a methodlessRequest method, if it throws an app_PageNotFoundException it will be ignored. On the rare occasion you want to do something that the parser doesn’t allow you can use this to handle your own casting for that part of your project.