Giter Site home page Giter Site logo

routes's Introduction

Routes

Hi, thanks for checking out Routes! Routes is low-level PHP class for defining and using URL routing patterns similar to CodeIgniter. In fact Routes is based on CodeIgniter's implementation.

Usage

To use Routes, you simply need to place the class somewhere accessible within your application. Then you need to define some routes and register them:

<?php
include('inc/routes.php');

Routes::add(array(
  'testing/(:num)' => 'test/$1',
  'posts/(:any)' => 'news/$1'
));

$origin = 'testing/1';
echo 'Origin: ' . $origin . '<br>';
echo 'Reroute: ' . Routes::route( $origin );

Why?

In-App Routing, as opposed to URL Rewriting (e.g. .htaccess/mod_rewrite), is a popular method for defining patterns for URLs in web sites and applications. It allows the developer to make an app appear one way, but underneath go another. It's most commonly found in MVC web frameworks (Rails, Sinatra, CakePHP, CodeIgniter et al). Routing is simple, but powerful, and could be really useful in situations outside of those frameworks.

There are other attempts at portable routing libraries, but they're too tied into the MVC framework schema to be useful outside. That's where Routes comes in. You could use it as your routing system for yet another framework (like I'm going to :D) or you can keep it completely separate, like I have needed to do lately.

Using Routes you can define complex routes using simple instructions and get the rewritten URL as a return variable in your code. So it doesn't need a specific web server. It doesn't do anything fancy, it just rewrites the URLs you give it according to the rules you supply, in the order you supplied them. Simple.

Hope you find it useful! :)

routes's People

Contributors

cnlpete avatar tarnfeld avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.