Login   Register  
PHP Classes
elePHPant
Icontem

File: sample.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Craig Smith  >  Cfw Router  >  sample.php  >  Download  
File: sample.php
Role: Example script
Content type: text/plain
Description: Sample usage of the Routing Engine
Class: Cfw Router
Map URIs to controller routes based on rules
Author: By
Last change:
Date: 2 years ago
Size: 922 bytes
 

Contents

Class file image Download
<?php
//include library
require_once('Cfw/Router.php');

//By Default routes will map as follows:
// / will map to default:index:index
// /x will map to x:index:index
// /x/y will map to x:y:index
// /x/y/z will map to x:y:z
// anything after will be keyed as params so
// /x/y/z/page/4 would map as module=x,controller=y,action=z,page=4

//custom routes::::
//one required route is the 404 route:

//get the instance:
$router Cfw_Router::getInstance();
// setStaticRoute - param1 url string, param 2 module/controller/action
$router->setStaticRoute('_404''error/index/notfound');

//setWileRoute - param1 url required (more can be after), param2 module, controller,action
$router->setWildRoute('news/:id''cms/news/list');
//route above would match as follows:
//url://dom.ext/news/1 - map to cms - news::list id=1
//url://dom.ext/news/1/page/2 - map to cms - news::list id=1 page=2