Skip to content

Routing

xolf edited this page Mar 10, 2016 · 3 revisions

app/route.php includes all routes in your project.

Open this file to controll your routes.

<?php

//FILLED WITH EXAMPLE DATA

$route = new Dreamcoil\Route;

$view = new Dreamcoil\View;

if($route->is('/hello')) $view->get('welcome.hello');

if($route->is('/profile/{id}/{name}')) echo 'Hey, ' . $route->data['name'];

if($route->is('/test') or $route->is('/session')) App\ExampleClass::called();

if($route->group('profile'))
{

    if($route->is('view')) echo 'view';

    if($route->is('edit')) echo 'edit';

}

Dreamcoil is using the Route class for routing and the View class for receiving the views from the folder structure.

Now we take a close look on the routing with Dreamcoil.

Route

The Route class offers several functions for routing.

The first one is is.

is

With $route->is(string) you can check if a specific route string got called.

So we check the return statement with a an if loop.

if($route->is('/hello')) echo 'Hello';

If you now type http://localhost/hello into your browser, you will see Hello.

Variables

Dreamcoil also supports it using custom variables in your URL structure.

eg. you want to echo a given user name from the URL.

The solution:

if($route->is('/hello/{name}')) echo 'Hello, ' . $route->data['name'];

Navigation

First use

Clone this wiki locally