Thule - 0.9.6
  • Welcome
  • Introduction
  • - MVC(Model-View-Controller)
    - Architecture of Framework
    - Flow Chart of Application
    - Services In One Server
    - Developing Guide
    - Features
  • Installation
  • Getting Started
  • - Direct Access HTTP
    - Router Access HTTP
    - Router Direct Access HTTP
    - Reserved Function
    - Convention
    - Bootstrap
    - Pack Javascript , CSS
  • Basic Modules
  • - Model
    - View
    - Controller
  • Libraries
  • - Router
    - Config
    - Response
    - Request
    - Database
    - Query
    - Cache
    - Debug
    - Log
    - Unit Test
    - Registry
    - Profile
  • Helper
  • - Auth
    - Calendar
    - Date
    - Error page
    - Email
    - Form
    - GeoIP
    - Google
    - Html Element
    - Html
    - Http
    - I18n
    - Image
    - Json
    - Jquery
    - Login
    - Layout
    - Locale
    - PHP to Javascript
    - Paging
    - Payflow
    - Soap
    - Text
    - Table
    - Uri
    - Upload
    - Validation
  • Plugins
  • - Smarty Template Engine
  • History
  • Home > Router

    Nowaday Router is to be very useful library because of need of seperating between url and view files.
    This router can help you to make your own uri very simply .

    Default Router - RDA(Router Direct Access)


    Router config file is a config/router_config.php.
    * Prefix "router_" must be in key.

    $config['router_access_mode']= array("View","Controller");

    Default is just same Direct Access Url (pure url).

    URL : http://yourdomain/path/index
    View : doctroot/path/index.php file

    If there are directories....
    URL : http://yourdomain/mvc/sub/subTemplate
    View : doctroot/mvc/sub/subTemplate.php file

    Controller is called in view file like below
    <?php $Frontend->load("Controller.action"); ?>
    <?php $Frontend->load(array("Controller.action","Controller1.action"));?>

    Default Router - RA (Router Access)


    $config['router_access_mode']= array("Controller","View");


    Default router,last one is method and previous last one is class.

    URL : http://yourdomain/mvc/withoutTemplate
    View : doctroot/mvc/withoutTemplate.php file
    Controller : CONTROLLER_PATH/mvc.php
          controller class: MvcController
          action method : withoutTemplate

    If there are directories....
    URL : http://yourdomain/mvc/sub/subTemplate
    View : doctroot/mvc/sub/subTemplate.php file
    Controller : CONTROLLER_PATH/mvc/sub.php
          controller class: SubController
          action method : subTemplate


    Using ":" For Defining variables


    Add rule. You can choose your uri and define the variables for request in router_config.php.

    /*
    * if url is starting with profile , Controller is profile and action is userinfo
    */
    $config['router_profile']= array('module'=>'profile/:username/:usernumber',
          'view'=>'vm/withoutTemplate',
          'Controller'=>'vm',
          'action'=>'withoutTemplate');


    ":" means define the variable
    Below is that "http://yourdomain/profile/thule/1234" ,username="thule" , usernumber="1234"

    URL : http://yourdomain/profile/thule/1234
    View : doctroot/vm/withoutTemplate.php file
    Controller : CONTROLLER_PATH/vm.php
          Controller class: Vm
          action method : withoutTemplate


    Below is that "http://yourdomain/1234" ,blogid="1234"

    $config['router_blog']= array('module'=>':blogid',
          'view'=>'index',
          'Controller'=>'index',
          'action'=>'blog');

    URL : http://yourdomain/1234
    View : doctroot/index.php file
    Controller : CONTROLLER_PATH/index.php
          Controller class: Index
          action method : blog


    Using "<var+value>" For Defining variables and values


    $config['router_profile']= array('module'=>'profile/:username/:usernumber/<var+value>',
          'view'=>'vm/withoutTemplate',
          'Controller'=>'vm',
          'action'=>'withoutTemplate');


    Below is that "http://yourdomain/profile/thule/1234/aaa/111/bbb/222" ,username="thule" , usernumber="1234" ,aaa="111" ,bbb="222"

    URL : http://yourdomain/profile/thule/1234/aaa/111/bbb/222
    View : doctroot/vm/withoutTemplate.php file
    Controller : CONTROLLER_PATH/vm.php
          Controller class: Vm
          action method : withoutTemplate

    Using "string*"


    "string*" means start with string .

    $config['router_index']= array('module'=>'index*',
          'view'=>'index',
          'Controller'=>'index',
          'action'=>'index');

    URL : http://yourdomain/index.php
    View : doctroot/index.php file
    Controller : CONTROLLER_PATH/index.php
          Controller class: Index
          action method : index

    Using "*string"


    "*string" means end with string .

    $config['router_index']= array('module'=>'*index',
          'view'=>'index',
          'Controller'=>'index',
          'action'=>'index');

    URL : http://yourdomain/phpindex
    View : doctroot/index.php file
    Controller : CONTROLLER_PATH/index.php
          Controller class: Index
          action method : index


    Add the Rule to Router


    You can add the rule in router_config.php with "$router" variable. Below is for example.

    $router['blog'] = array('module'=>':userid',
          'view'=>'index',
          'controller'=>'index',
          'action'=>'blog'
          );

    /*
    * if url is starting with profile , controller is vm and action is f1
    * uri=>profile/kenneth/1234..
    */
    $router['profile'] = array('module'=>'profile/:username/:usernumber',
          'view'=>'mvc/withoutTemplate',
          'controller'=>'mvc',
          'action'=>'profile');

    /*
    * if url is starting with vm , uri=> vm/var/value/var/value/....
    */
    $router['vm'] = array('module'=>'vm/<var+value>',
          'view'=>'mvc/withoutTemplate',
          'controller'=>'mvc',
          'action'=>'vm');
    /*
    * if url is starting with profilevar , controller is vm and action is f1
    * uri=>profilevar/kenneth/1234/var/value/var/value....
    */
    $router['profilevar'] = array('module'=>'profilevar/:username/:usernumber/<var+value>',
          'view'=>'mvc/withoutTemplate',
          'controller'=>'mvc',
          'action'=>'profilevar');

    No view is very useful in case of Ajax


    Sometimes when we use the ajax just want to get the data from database without views,at that time you can make it without views.

    Router Exception


    If you want to skip special directory from the router in parsing url,add the value to configure of router (config/router_config.php).

    /**
    * Router has a exception , if url has a one of router_exception , the url should be passed to direct url
    */
    $router['viewaccess']= array('module'=>array('errors','elements')); // no controller ,don't through controller in previous.
    $router['controlleraccess']= array('module'=>array('*proc','*ajax')); //url finished with proc ,ajax,there is no view, just controller access.