Studyon Minte9.com
ZF 1.0




Regex



Application/config/routes.ini
------------------------------

...

;ARTICLE
routes.article.type = "Zend_Controller_Router_Route_Regex"
routes.article.route = "([a-z_-]+)/([a-z0-9-_.]+)_(d+)"
routes.article.defaults.module = "default"
routes.article.defaults.controller = "frontend"
routes.article.defaults.action = "article"
routes.article.map.1 =  category
routes.article.map.2 =  slug
routes.article.map.3 =  article_id
routes.article.reverse =  "%s/%s_%s"


Application/modules/default/controllers/FrontendController.php
-----------------------------------------------------------------
<?php
class FrontendController extends Zend_Controller_Action {

	...

	public function testAction() {
		$params = $this->getRequest()->getParams();
		$this->view->message = "Page: " . $params['page'];
	}

	public function articleAction() {
		$params = $this->getRequest()->getParams();
		var_dump($params); die;
	}
}

// Display:
	1) http://zfsite/news/news_slug_22' target='_blank'>http://zfsite/news/news_slug_22
		array(6) {
		  ["category"]=>
		  string(4) "news"
		  ["slug"]=>
		  string(9) "news_slug"
		  ["article_id"]=>
		  string(2) "22"
		  ["module"]=>
		  string(7) "default"
		  ["controller"]=>
		  string(8) "frontend"
		  ["action"]=>
		  string(7) "article"
		}
	2) http://zfsite/news/news_slug
		not found (article_id missing)
	3) http://zfsite/test/2 - display (Page: 2)
	4) http://zfsite/test/2_1
		array(6) {
		  ["category"]=>
		  string(4) "test"
		  ["slug"]=>
		  string(1) "2"
		  ["article_id"]=>
		  string(1) "1"
		  ["module"]=>
		  string(7) "default"
		  ["controller"]=>
		  string(8) "frontend"
		  ["action"]=>
		  string(7) "article"
		}
	5) http://zfsite/test/2/1
		not found (route not found)


//zend_controller.router


http://www.vayanis.com/2009/03/20/intro-to-zend-framework-routing/
http://framework.zend.com/manual/en/zend.controller.router.html