Skip to content
Bob Magic II edited this page Aug 23, 2022 · 8 revisions

This is a really quick skim of how you could get the library up and running.

Example Project Directory Structure

routes/
	Home.php

www/
	index.php

composer.json
routes.phson

Step 0: Setup URL Rewriting.

Your webserver will need to be told to pump all requests that do not really exist, as in not real files and folders in your web root, to your request router usually named index.php.

Example Config for Apache 2.4 via .htaccess in www folder

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php [QSA,L]

Step 1: Install Avenue

First we need a new directory called routes to contain all the route class files and have Composer autoload from. This will tell it to seek for anything in the Routes namespace to the routes directory in the example project at the start of this guide. It is best to have all your routes (aka controllers) in their own directory so that the directory scanner won't have to wade through gallons of crap it does not care about. You can also use any already configured autoloading directory, but it is strongly suggested all routes still go into a sub-directory only for routes.

"autoload": {
	"psr-4": {
		"Routes\\": "routes/"
	}
}

Then install the library.

$ composer install netherphp/avenue

Step 2: Setup Router (www/index.php).

On a fresh project it is very likely your index.php only need be a few lines long.

<?php

require('vendor/autoload.php');

$Config = new Nether\Object\Datastore;
Nether\Avenue\Library::Init($Config);

$Router = new Nether\Avenue\Router($Config);
$Router->Run();

Step 3: Create A Route (routes/Home.php)

<?php

namespace Routes;

use Nether\Avenue\Route;
use Nether\Avenue\Meta\RouteHandler;

class Home
extends Route {

	#[RouteHandler('/index')]
	public function
	Index():
	void {

		echo 'Home Page';
		return;
	}

}
  • See -link- for more route and attribute info, including specifying Domains, HTTP Verbs, and extracting info from the URLs.

Step 4: Compile Static Route Map (routes.phson)

This is technically optional.

If you do not compile the route map to a static file it will scan the directory every page hit. This is OK while you are greenfielding but on production you will want to use a cache.

$ vendor/bin/netherave gen --show
Route Directory: routes
Route File: ./routes.phson

Summary:
 * GET (1)
   Routes\Home::Index

From this point on any time you hit the root of this website it will run the router and determine to execute Routes\Home::Index() method.