PHP code example of cooky / url-router

1. Go to this page and download the library: Download cooky/url-router 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/ */

    

cooky / url-router example snippets


/* main index.php */
te;

/* basic get */
Route::get('/', function (){
    echo '<h2>home page</h2>';
});

/* controller */
Route::get('/home', 'Home@Index');

/* with parameter */
Route::get('user/profile/{id}', 'User@Profile');

Route::post('test/post/{id}', function ($id){
    echo $id;
});

Route::complete();

/* layout.php */
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <link rel="stylesheet" href="css/default.css">
    
    <!-- Custom Css -->
    @yield(css)

    <title>routy basic templating</title>
</head>
<body>
    <!-- NAV -->
    <nav>NAV</nav>

    <!-- Dynamic Content -->
    @yield(content)

    <!-- FOOTER -->
    <footer>FOOTER</footer>

    <script src="node_modules/vue/dist/vue.js"></script>
    <!-- Dynamic Script -->
    @yield(script)
</body>
</html>

/* home.php */
 

 use View\Loader;

/* Home controller - every controller must be extends with Loader for view */
class Home extends Loader
{
    public function index(){
        $data['test'] = 'hello kitty';
        $this->view('main', $data);
    }
}