PHP code example of lastguest / aleph

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

    

lastguest / aleph example snippets









// The index route
get('/',function(){
  echo "<h1>Hello!</h1>";
});

// Listen POST on /
post('/',function(){
  echo "<h1>Received POST Data:</h1><pre>";
  print_r($_POST);
  echo "</pre>";
});

get('/api/todos',function(){
  return [
    [ "id"=>1, "text"=>"Write documentation" ],
    [ "id"=>2, "text"=>"Smile" ],
    [ "id"=>3, "text"=>"Play more games" ],
    [ "id"=>4, "text"=>"Conquer the World" ],
  ];
});

database('init','mysql:host=localhost;dbname=test','root','root');

$uid = sql_value('select id from users where username = ? limit 1', array($username));

$user = sql_row('select * from users where username = ?', array($username));
echo $user->email;

sql_each('select * from users', function($user){
  echo "<li><a href="mailto:{$user->email}">{$user->name}</a></li>";
});

sql_each('select * from users where activated = ?', function($user){
  echo "<li><a href="mailto:{$user->email}">{$user->name}</a></li>";
}, array('YES'));

if ( sql('delete from users where id = ?',array(123)) ) echo "User deleted.";

class TestService {
	public $value;
	function __construct($x){ $this->value = $x; }
}

service('test',function($x){
	return new TestService($x);
});

$a = service('test',3);
$b = service('test',5);

service('test',function($x){
	static $instance = null;
	return $instance === null ? $instance = new TestService($x) : $instance;
});

$a = service('test',3);
$b = service('test',5);
$c = service('test');