rawphp/raw-router

RawRouter is a simple router used by RawPHP framework and other applications.

dev-master / 0.x-dev 2014-12-22 21:37 UTC

This package is auto-updated.

Last update: 2024-04-20 06:59:06 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads Latest Unstable Version License

SensioLabsInsight

Package Features

  • Simple to use router
  • MVC style routing

Installation

Composer

RawRouter is available via Composer/Packagist.

Add "rawphp/raw-router": "0.*@dev" to the require block in your composer.json and then run composer install.

{
        "require": {
            "rawphp/raw-router": "0.*@dev"
        }
}

You can also simply run the following from the command line:

composer require rawphp/raw-router "0.*@dev"

Tarball

Alternatively, just copy the contents of the RawRouter folder into somewhere that's in your PHP include_path setting. If you don't speak git or just want a tarball, click the 'zip' button at the top of the page in GitHub.

Basic Usage

<?php

use RawPHP\RawRouter\Router;

// configuration
$config = array(
    'default_controller' => 'home',                             // the controller that will handle requests if the requested controller is not found
    'default_action'     => 'index',                            // the default action (method) to call if the requested action is not found
    'namemspace'         => 'RawPHP\\RawRouter\\Controllers\\', // the controllers namespace, leave empty if namespaces are not used
);

// get new router instance
$router = new Router( );

// initialise router
$router->init( $config );

// example request
// http://example.com/users/get/1

$route = 'users/get';                                           // the route must be in one of the following formats [ controller, controller/action, controller/action/param/param/... ]
$params = array( 1 );                                           // array of values to be passed to the action method in the correct order

// create controller
$controller = $router->createController( $route, $params );

// run controller action
$controller->run( );

License

This package is licensed under the MIT. Read LICENSE for information on the software availability and distribution.

Contributing

Please submit bug reports, suggestions and pull requests to the GitHub issue tracker.

Changelog

22-09-2014

  • Tested on PHP 5.3

20-09-2014

  • Replaced php array configuration with yaml

18-09-2014

  • Added loadView() method to Controller which can load html templates
  • Added LEController that extends Controller and provides languages features. It can load different language translations required for use in html templates.
  • Updated to work with the latest rawphp/rawbase package.
  • Added init() methods to both Controllers to ensure that the controller gets initialised properly.

17-09-2014

  • Updated to work with the latest rawphp/rawbase package.
  • Added extra hooks to Action.
  • Removed the constructor added new setAction( IAction ) method on Controller.

14-09-2014

  • Implemented the hook system.
  • Renamed RawController -> Controller.

12-09-2014

  • Changed router constructor to take a configuration array rather than individual parameters.

11-09-2014

  • Initial Code Commit