PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Roman Krivosheev   Simple Route   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example 1
Class: Simple Route
Parse and build URIs from routing rules
Author: By
Last change: New algorithm of parse URL
Date: 12 years ago
Size: 1,618 bytes
 

Contents

Class file image Download
<?php

   
function pre($url, $str){
        echo
"<pre style='background:#f1f1f1;border:1px solid #b1b1b1;padding:10px;margin:10px 0;'>$url\n\r".print_r($str, true)."</pre>";
    }
   
//Include ROUTE CLASS:
   
include dirname(__FILE__).'routeclass.php';

   
Route::$request[] = array(
        array(
           
'request' => '/',
           
'action' => 'index',
           
'test' => 'go' // an additional parameter
       
),
        array(
           
'request' => '/<lang>/catalog(/<test>)', // key url section
           
'action' => 'catalog_review'
       
),
        array(
           
'request' => '/news(/page/<pagination>|/<page>)', // key url section
           
'action' => 'news',
        ),
        array(
           
'request' => '/<lang>/<action>', // key url section
           
'action' => 'page' // default action in url
       
),
       
'controller' => 'main',
       
'param' => array(
           
'lang' => '[a-z]{2}', // regex url parametr <lang>
           
'action' => '(contact|servise|go|[a-z]{5,25})', // regex url parametr <action>
           
'page' => '[a-z0-9_\-]{5,25}',
           
'pagination' => '[0-9]{1,2}',
           
'year' => '[0-9]{4}'
       
)
    );


   
pre('/', Route::matchURI('') );

   
pre('/ru/import', Route::matchURI('/ru/import') );

   
pre('/ru/go', Route::matchURI('/ru/go') );

   
pre('/ru/catalog', Route::matchURI('/ru/catalog') ); // OR /ru/catalog/additional_parameter

   
pre('/news/page/23', Route::matchURI('/news/page/23') );

   
pre('/news/title_news', Route::matchURI('/news/title_news') );