YaRouter assumes 2 things.
You are, through your server or document root config file, directing all traffic through a single entry point/bootstrap file; such as index.php.
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...
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
Next create a new YaRouter() object.
Finally, call the get_view() method and define your parameters. get_view requires 3 arguements:
$location This is the path to the main directory (without the trailing slash) where all of your views are stored.
$default The name of the default view file (without the extension). Typically used for home or index page.
$type This is the _type_ of view file you are calling (without the dot). E.g., html, php, etc...
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 );
1 Your views can use any extension. E.g., .htm, .html, .md, .php, etc..., but they must all be the same type.