PHP code example of zweifisch / zf
1. Go to this page and download the library: Download zweifisch/zf 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/ */
zweifisch / zf example snippets
= new zf\App;
/**
* @param int $times an optional param
*/
$app->get('/hello/:name', function($name, $times=1) {
return ['hello' => $name, 'times' => $times];
});
$app->get('/', function() {
return $this->render('landing-page');
});
$app->resource('post', 'user');
$app->run();
= new zf\App;
/**
* @param string $name your name
* @param int $times times to repeat
*/
$app->cmd('hello <name>', function($name, $times=1) {
return str_repeat("hello $name\n", $times);
})
/**
* @param bool $showDate also print date
*/
$app->cmd('time', function($showDate=false) {
return date($showDate ? 'Y-m-d H:i:s' : 'H:i:s');
});
$app->run();
$ php -S localhost:8000/index.php &> /tmp/server.log
$ curl localhost:8000/hello/foo?times=3
{"hello": "foo", "times': 3}
sh
$ php cli.php
Usage:
php cli.php hello <name>
name your name
--times times to repeat
php cli.php time
--show-date also print date
sh
$ php cli.php hello --times=2 zf
hello zf
hello zf