本文整理汇总了PHP中Route::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::add方法的具体用法?PHP Route::add怎么用?PHP Route::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Route
的用法示例。
在下文中一共展示了Route::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Route
<?php
$route = new Route();
$route->add('', array('controller' => 'TestApp'));
$route->add('index', array('controller' => 'TestApp', 'action' => 'index'));
$route->add('post', array('controller' => 'TestApp', 'action' => 'post'));
$route->add('post_with_get_params', array('controller' => 'TestApp', 'action' => 'post_with_get_params'));
$route->add('upload', array('controller' => 'TestApp', 'action' => 'upload'));
$route->add('multiple_template', array('controller' => 'TestApp', 'action' => 'multiple_template'));
$route->add('500', array('controller' => 'TestApp', 'action' => 'error_500'));
$route->add('without_view', array('controller' => 'TestApp', 'action' => 'without_view'));
示例2: Route
<?php
/**
* Routing system
*/
$route = new Route();
// User define function
$route->add('/h', function () {
echo 'hey this is home page';
});
// Routing controller
$route->add('/login', 'login');
$route->add('/account', 'account');
$route->add('/dashboard', 'dashboard');
$route->add('/error', 'error');
$route->add('/home', 'home');
//
$route->run();
示例3:
<?php
Route::add('any', '/', 'Controllers\\Guest\\PageController::home');
Route::add('get', '/contact/<?name?>', 'Controllers\\Guest\\PageController::contact');
Route::add('post', '/upload', 'Controllers\\Guest\\PageController::upload');
示例4: simulate_uri
<?php
require 'Route.php';
function simulate_uri($uri)
{
foreach (Route::all() as $route) {
$route->compile();
if ($route->matches($uri)) {
//var_dump($route->getData());
call_user_func_array($route->getCallback(), $route->getData());
}
}
}
/* Tests */
Route::add('site/test', 'SiteController::contactAction');
Route::add('{controller}/{action}/{id?}', function ($controller, $action, $id) {
echo $controller, ' ', $action, ' ', $id;
})->where('action', 'user');
Route::add('{controller}/{action}/{id}', function ($controller, $action, $id) {
echo sprintf('Te saluta %s::%s(%s) ^_^', $controller, $action, $id);
})->where('id', '[0-9]+');
Route::add('{lang}/{controller}/{action?}', function ($lang, $controller, $action = null) {
});
simulate_uri('user/settings/1005321');
示例5: function
<?php
/*
| Project: fw
| Description: my framework
| Author: Pham Ngoc Phu
| Alias: Phu Master
| Email: phumaster.dev@gmail.com
*/
/*
* all route
*/
Route::add('/', 'WelcomeController@hello');
Route::add('/phumaster', function () {
var_dump(get('test'));
var_dump($_SESSION);
});
Route::add('/{name}', function ($name) {
return view('welcome', compact('name'));
});
示例6: Route
<?php
/**
* Routing system
*/
$route = new Route();
$route->add('/', function () {
echo json_encode("BKSOICT SERVER SERVICE!");
});
// Routing controller
$route->add('/login', 'login');
$route->add('/logout', 'logout');
$route->add('/group', 'group');
$route->add('/notification', 'notification');
$route->add('/schedule', 'schedule');
$route->add('/student', 'student');
$route->add('/user_class', 'user_class');
$route->add('/user', 'user');
$route->add('/class_room', 'class_room');
$route->add('/session', 'session');
//
$route->run();
示例7: Route
<?php
/* Route example */
$route = new Route('example', 'Index');
// Creating a route with a controller, the model will be extracted by the getModel method
$route->add(array('', 'index.html'), function () {
// When the url is index.html -> call Closure
echo 'Hello world';
});
$route->add(array('article-{id}.html', 'id' => '[0-9]+'), Query('getArticle', Get('id')), Action('showArticle'));
// Calling model method getArticle and giving result to controller method showArticle
$route->add(array('articles.html/{page?}', 'page' => '[0-9]+'), Query('getArticles', array(Get('page'), QUERY_ELSE => 0)), Action('showArticles'));
// Then feeding the result to showArticles method
$route->add('article-create', Permission(), Event('getFormEvent', array(Query('newArticle', Get('name')), Action('showArticle'), EVENT_ELSE => Action('writeArticle'))));
// // If the form isn't completed, show the writeArticle form
return $route;
示例8: Route
<?php
// create routes object
$route = new Route();
// add top level routes & corisponding controllers
$route->add('/', 'homeController');
$route->add('/login', 'loginController');
$route->add('/logout', 'logoutController');
示例9: function
<?php
/*
* Aca se agregan las rutas
*/
Route::add('/', 'Main@StartView');
Route::add('/other_method', 'Main@StartView@otherMethod');
Route::add('/anonymous', function () {
echo 'This is an anonymous function.';
});
示例10: Route
<?php
// Routes Config
//
// Routes are based on simple regular expressions
//
// - Two types, manual routing and auto routing
//
// - These are in order of adding so put catch-alls last
// and specific routes first.
namespace lib;
$routes = new Route(isset($_GET['url']) ? $_GET['url'] : 'index');
$routes->add(array('name' => 'home page', 'type' => 'manual', 'route' => '/^index$/', 'controller' => 'pages', 'action' => 'index', 'params' => isset($_GET['url']) ? $_GET['url'] : 'index'));
$routes->add(array('name' => 'controlled pages', 'type' => 'auto', 'route' => '/^(?<controller>[0-9A-Za-z-_]+)?\\/?(?<action>[0-9A-Za-z-_]+)?\\/?(?<params>[0-9A-Za-z-_]+)?\\.?(?<ext>.*)?\\/?/'));
// add the 404 route last
$routes->add(array('name' => '404', 'type' => 'manual', 'route' => '/.*/', 'controller' => 'error', 'action' => 'fourohfour'));
示例11: define
<?php
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
//we need to go through and initialize all of the modules we need to use
Jx_Modules::init();
Route::add('media', 'media/<action>/<file>(.<ext>)', null, 'admin')->defaults(array('controller' => 'media'));
//add event callbacks as needed
Jx_Event::addObserver(array('Jx_Modules', 'onGetAdminMenu'), 'getAdminMenu');
Jx_Event::addObserver(array('Jx_Settings', 'onGetAdminMenu'), 'getAdminMenu');
示例12: __autoload
<?php
include '../lib.php';
function __autoload($class)
{
$file_path = 'lib/' . $class . '.php';
if (file_exists($file_path) == false) {
$file_path = 'controllers/' . $class . '.php';
}
require_once $file_path;
}
$route = new Route();
$route->add(['/about', '/contact']);
$route->submit();
示例13: debug_backtrace
/**
* @param string $method
* @param string $url
* @param array $destination
* @retun \Route\Path
*/
public static function &addRoute($method, $url, $destination, $name)
{
$bt = debug_backtrace();
$file = $bt[0]['file'];
if (isset($bt[0]['class'])) {
$class = $bt[0]['class'];
}
if (strpos($destination, '.') !== false) {
$expl = explode('.', $destination);
$destClass = $expl[0];
$destMethod = $expl[1];
$oReflectionClass = new ReflectionClass($class);
$namespace = $oReflectionClass->getNamespaceName();
if (substr($destClass, 0, 1) == "\\") {
if (isset($class)) {
self::$routes[$name] = ['call' => [$destClass, $destMethod], 'caller' => ['class' => $class, 'file' => $file]];
} else {
self::$routes[$name] = ['call' => [$destClass, $destMethod], 'caller' => ['file' => $file]];
}
} else {
$cl = "\\" . $namespace . "\\" . $destClass;
if (isset($class)) {
self::$routes[$name] = ['call' => [$cl, $destMethod], 'caller' => ['class' => $class, 'file' => $file]];
} else {
self::$routes[$name] = ['call' => [$cl, $destMethod], 'caller' => ['file' => $file]];
}
}
} else {
if (isset($class)) {
self::$routes[$name] = ['call' => [$class, $destination], 'caller' => ['class' => $class, 'file' => $file]];
} else {
self::$routes[$name] = ['call' => $destination, 'caller' => ['file' => $file]];
}
}
return \Route::add($method, $url, 'ModuleController.' . $name);
}
示例14: array
<?php
Route::add('users', 'user(/<action>)', null, 'admin')->defaults(array('controller' => 'user', 'action' => 'login'));
Route::add('user_admin', 'admin/user/<action>(.<format>)', array('format' => 'html|xml|json|rss'), 'admin')->defaults(array('directory' => 'admin', 'controller' => 'user', 'format' => 'json'));
示例15: Route
<?php
include 'route.php';
$route = new Route();
$route->add('/');
$route->add('/news');
$route->add('/contact');
echo '<pre>';
print_r($route);
$route->submit();