PHP code example of cakesuit / route

1. Go to this page and download the library: Download cakesuit/route library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cakesuit / route example snippets



...

Plugin::load('Cakesuit/Route');



public function initialize()
{
    $this->loadHelper('Cakesuit/Route.Route');
}



Route::scope('/', function (RouteBuilder $routes) {
    $routes->connect('/users', ['controller' => 'Users', 'action' => 'index'], ['_name' => 'users:index']);
    $routes->connect('/users/:id', ['controller' => 'Users', 'action' => 'view'], ['_name' => 'users:view']);
    // OR with verbe GET if you use version >= 3.5.0
    $routes->get('/users', ['controller' => 'Users', 'action' => 'index'], 'users:index');
    $routes->get('/users/view/:id', ['controller' => 'Users', 'action' => 'view'], 'users:view');
});


 
// Génarate tag A with url
// link($routename, $title, array $params = [], array $options = [])
echo $this->Route->link('user:index', 'Users');
// return <a href="/users">Users</a>
echo $this->Route->link('user:view', 'View User', ['id' => $user->id], ['title' => 'username ' . $user->username]);
// return <a href="/users/view/1" title="username Fred">View User</a>

// Generate url
// url($routename, array $params = [], $fullbase = false)
echo $this->Route->url('user:index');
// return /users
echo $this->Route->url('user:view', ['id' => $user->id], true);
// return http://localhost:8765/users/view/1