PHP code example of sigareng / nam

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

    

sigareng / nam example snippets


use sigareng\Nam\Nam;

Nam::get('/', function() {
  echo 'Hello world!';
});

Nam::dispatch();


use sigareng\Nam\Nam;

Nam::get('/', function() {
  echo 'Hello world!';
});

Nam::dispatch();



use sigareng\Nam\Nam;

Nam::get('/', function() {
  echo 'Hello world!';
});

Nam::dispatch();

Nam::get('/(:any)', function($slug) {
  echo 'I get : ' . $slug;
});

Nam::dispatch();

Nam::get('/', function() {
  echo 'Im a GET request!';
});

Nam::post('/', function() {
  echo 'Im a POST request!';
});

Nam::any('/', function() {
  echo 'I can be both a GET and a POST request!';
});

Nam::dispatch();


use Nam\Nam;

Nam::get('/', function() {
  Nam::render('./view/head.php');
  Nam::render('./view/body.php');
  Nam::render('./view/footer.php');
});

Nam::dispatch();

Nam::get('/(:num)', function($val) {
  $age['alice']=$val;
  Nam::render('./hi.php',$age);
//   echo '<pre>' . print_r(get_defined_vars(), true) . '</pre>';
});

echo 'hola, age alice is :'.$data['alice'];

Nam::error(function() {
  echo '404 :: Not Found';
});



use Nam;

Nam::get('/', 'Controllers\see@index');
Nam::get('page', 'Controllers\see@page');
Nam::get('view/(:num)', 'Controllers\see@view');

Nam::dispatch();


namespace Controllers;

class Demo {

    public function index()
    {
        echo 'home';
    }

    public function page()
    {
        echo 'page';
    }

    public function view($id)
    {
        echo $id;
    }

}