YaRouter

The repo.

Overview

YaRouter assumes 2 things.

  1. You are, through your server or document root config file, directing all traffic through a single entry point/bootstrap file; such as index.php.

  2. Your views file-names reflect your URL structure. For example, If your URL is example.com/foo/bar/my-page, YaRouter expects to find the view for this page at path/to/templates/foo/bar/my-page.html. [1].

    Example:

    /views
      |
      |__index.html         (example.com)<-default view
      |
      |__/about
      |   |
      |   |_team.html       (example.com/about/team)
      |   |
      |   |_products.html   (example.com/about/products)
      |
      |__/services
          |
          |_service1.html   (example.com/services/service1)
          |
          |_service2.html   (example.com/services/service2)
          |
          |_service3.html   (example.com/services/service3)
    
    ...etc...
    
  1. Set up your index.php file (or whatever file you are pointing your inbound requests to). If you are using an autoloader, like composer Start by requiring the autoloader script: require __DIR__ . '/vendor/autoload.php';. Then use the SageworksStudio\YaRouter. If you're not using an autoloader just include the YaRouter.php script

  2. Next create a new YaRouter() object.

  3. Finally, call the get_view() method and define your parameters. get_view requires 3 arguements:

Kitchen Sink Example:

This example assumes you're using an autoloader. Otherwise just include the YaRouter class in your bootstrap file.

(index.php)

require __DIR__ . '/vendor/autoload.php';

use SageworksStudio\YaRouter;

$location = 'path/to/views';
$default = 'index';
$type = 'html';

$r = new YaRouter();
$r->get_view( $location, $default, $type );

Appendix

1 Your views can use any extension. E.g., .htm, .html, .md, .php, etc..., but they must all be the same type.