本文整理汇总了PHP中Application::map方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::map方法的具体用法?PHP Application::map怎么用?PHP Application::map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Application
的用法示例。
在下文中一共展示了Application::map方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
use Koi\CLI;
// Create our application
class Application extends Koi\Application
{
public function __construct()
{
CLI::$banner = 'Usage: php cli.php [command] [switches]';
CLI::set_opt(NULL, 'help', 'Show this help message');
CLI::set_opt('name', 'name', 'Specify your name', TRUE);
}
public function index()
{
CLI::show_help();
}
public function name()
{
if (CLI::get_opt('help') === NULL) {
CLI::show_help('name');
exit;
}
$name = CLI::get_opt('name');
if ($name === FALSE) {
CLI::terminate('name', 'You need to specify a name');
}
echo "Your name is {$name}" . PHP_EOL;
}
}
$app = new Application();
$app->map('/', 'index');
$app->map('/name', 'name');
$app->run();
示例2: index
<?php
require_once __DIR__ . '/../lib/koi.php';
// Create our application
class Application extends Koi\Application
{
public function index()
{
return "Hello, world!";
}
public function not_found()
{
return array("The requested page could not be found", 404);
}
}
$app = new Application();
$app->map('/', 'index');
$app->map('/:404', 'not_found');
$app->run();
示例3: regex
{
return "alphanumeric method";
}
public function regex()
{
return "regex method";
}
public function not_found()
{
return "404 method";
}
public function sub_not_found()
{
return "sub 404 method";
}
public function route_args($number)
{
return "route with args method {$number}";
}
}
$app = new Application();
$app->map('/', 'index');
$app->map('/:alpha', 'alphabetic');
$app->map('/hello/world', 'sub_route');
$app->map('/:numeric', 'numeric');
$app->map('/:alphanumeric', 'alphanumeric');
$app->map('/koi-([a-zA-Z0-9])+', 'regex');
$app->map('/route_args/:numeric', 'route_args:args');
// Note that in order to prevent collisions 404 routes should be added at the very end.
$app->map('/:alphanumeric/:404', 'sub_not_found');
$app->map('/:404', 'not_found');
示例4: index
<?php
class Application extends Koi\Application
{
public function index()
{
return "Hello, index!";
}
public function param($name, $surname)
{
return "hello {$name} {$surname}";
}
}
$app = new Application();
$app->map('/', 'index');
$app->map('/param', 'param:args');
示例5: index
<?php
class Application extends Koi\Application
{
public function index()
{
return array("index method", 200, "text/html");
}
public function not_found()
{
return array("not_found method", 404, "text/html");
}
public function no_content()
{
return array("no_content method", 200);
}
}
$app = new Application();
$app->map('/', 'index');
$app->map('/not_found', 'not_found');
$app->map('/no_content', 'no_content');
示例6: index
require_once __DIR__ . '/../../lib/koi.php';
use Koi\Cookie;
class Application extends Koi\Application
{
public function index()
{
$c = new Cookie('name', 'Yorick Peterse', NULL, '/', time() + 86400);
$c->save();
return $c->value;
}
public function name()
{
$c = new Cookie('name');
return $c->value;
}
public function delete()
{
$c = new Cookie('name');
if ($c->destroy()) {
return "Cookie destroyed";
} else {
return "Failed to destroy the cookie";
}
}
}
$app = new Application();
$app->map('/', 'index');
$app->map('/name', 'name');
$app->map('/delete', 'delete');
$app->run();
示例7:
<?php
include 'lib/bootstrap.php';
Application::map('(.*)', 'Welcome');
Application::run();