GithubHelp home page GithubHelp logo

choco-routes-php's Introduction

Choco Routes

Route System for URL Friendly with PHP

A simple route system based in PHP for your website or projects

Important Note

All your HTML pages must have defined the meta tag base, this example comes with a built-in variable $base_href to set this tag value dinamically. This meta tag helps mantain all your links working properly.

<base href="<?php echo $base_href; ?>">

Usage

Download files and open _routes.php to custom your project routes.

File "_routes.php"

Matching URLS

Use the function match_url() to match url's and show your content.

Show homepage

if( is_homepage() ){
	include 'home.php';
	exit;
}

Show a single file

if( match_url('contact-us') ){
	include 'contact.php';
	exit;
}

URL's with Parameters / Variables

Define your URL pattern, there is two possible values: {str} to match strings like slugs and {int} to match integers like ID's.

And for obtain the values in the URL use the function get_param() and use pattern {this} to indicate the script wich data you require.

if( match_url('services/{str}/{int}') ){

	//ID
	$id = get_param('services/{str}/{this}');
	
	//Slug
	$slug = get_param('services/{this}/{int}');

	include 'services.php';
	exit;

}

Error 404

If you don't have a 404.php file in your root folder the message of error will be taken from the default folder core/defaults/errors/404.php.

License

This software is released under the MIT License.

Author: Carlos Maldonado @choquo.

You can use this code in commercial and open source projects, if you use this code for your projects just give me a mention and share this repo in your social networks.

2/26/2016 12:14:40 PM

choco-routes-php's People

Contributors

imcarlosdev avatar

Watchers

 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.