本文整理汇总了PHP中Route::map方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::map方法的具体用法?PHP Route::map怎么用?PHP Route::map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Route
的用法示例。
在下文中一共展示了Route::map方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: expose
/**
* Enable REST routes to expose a resource.
*
* Example:
* <code>
* // Create a new '/bucket' route group.
* REST::expose('bucket',[
* 'create' => function(){ echo "New bucket"; },
* 'read' => function($id){ echo "SHOW bucket($id)"; },
* 'update' => function($id){ echo "MODIFY bucket($id)"; },
* 'delete' => function($id){ echo "DELETE bucket($id)"; },
* 'list' => function(){ echo "All buckets"; },
* 'clear' => function(){ echo "Cleared all buckets"; },
* ]);
*
*
*
* Route::group('/non_conventional_/route/base',function(){
* // Create directly the REST routes (for use inside another parent group).
* REST::expose([
* 'create' => function(){ echo "New bucket"; },
* 'read' => function($id){ echo "SHOW bucket($id)"; },
* 'update' => function($id){ echo "MODIFY bucket($id)"; },
* 'delete' => function($id){ echo "DELETE bucket($id)"; },
* 'list' => function(){ echo "All buckets"; },
* 'clear' => function(){ echo "Cleared all buckets"; },
* ]);
* });
*
* </code>
*
* @param string $element The resource name.
* @param array $maps A map of actions callbacks for different CRUD actions.
*/
public static function expose($element, array $maps = null)
{
if (null === $maps && is_array($element)) {
$maps = $element;
$collection = '';
} else {
$collection = '/' . $element;
}
return Route::group($collection, function () use($maps) {
$actions = [];
if (isset($maps['list'])) {
$actions['get'] = $maps['list'];
}
if (isset($maps['create'])) {
$actions['post'] = $maps['create'];
}
if (isset($maps['clear'])) {
$actions['delete'] = $maps['clear'];
}
Route::map('/', $actions);
$actions = [];
if (isset($maps['read'])) {
$actions['get'] = $maps['read'];
}
if (isset($maps['update'])) {
$actions['put'] = $maps['update'];
}
if (isset($maps['delete'])) {
$actions['delete'] = $maps['delete'];
}
Route::map("/:id", $actions);
});
}
示例2: expose
/**
* Enable REST routes to expose a resource.
*
* Example:
* <code>
* // Create a new '/bucket' route group.
* REST::expose('bucket',[
* 'create' => function(){ echo "New bucket"; },
* 'read' => function($id){ echo "SHOW bucket($id)"; },
* 'update' => function($id){ echo "MODIFY bucket($id)"; },
* 'delete' => function($id){ echo "DELETE bucket($id)"; },
* 'list' => function(){ echo "All buckets"; },
* 'clear' => function(){ echo "Cleared all buckets"; },
* ]);
*
*
*
* Route::group('/non_conventional_/route/base',function(){
* // Create directly the REST routes (for use inside another parent group).
* REST::expose([
* 'create' => function(){ echo "New bucket"; },
* 'read' => function($id){ echo "SHOW bucket($id)"; },
* 'update' => function($id){ echo "MODIFY bucket($id)"; },
* 'delete' => function($id){ echo "DELETE bucket($id)"; },
* 'list' => function(){ echo "All buckets"; },
* 'clear' => function(){ echo "Cleared all buckets"; },
* ]);
* });
*
* </code>
*
* @param string $element The resource name.
* @param array $maps A map of actions callbacks for different CRUD actions.
*/
public static function expose($element, array $maps = null)
{
if (null === $maps && is_array($element)) {
$maps = $element;
$collection = '';
} else {
$collection = '/' . $element;
}
$collection_routes = [];
if (isset($maps['list'])) {
$collection_routes['get'] = $maps['list'];
}
if (isset($maps['create'])) {
$collection_routes['post'] = $maps['create'];
}
if (isset($maps['clear'])) {
$collection_routes['delete'] = $maps['clear'];
}
Route::map($collection . '/', $collection_routes);
$entity_routes = [];
if (isset($maps['read'])) {
$entity_routes['get'] = $maps['read'];
}
if (isset($maps['update'])) {
$entity_routes['put'] = $maps['update'];
}
if (isset($maps['delete'])) {
$entity_routes['delete'] = $maps['delete'];
}
Route::map($collection . "/:id", $entity_routes);
}
示例3: handle
/**
* {@inheritdoc}
*/
public function handle(\Request $request)
{
$responseObject = new \Response();
self::$response = $responseObject;
self::$request = $request;
\DI::addInstance($responseObject);
\Route::map();
$connection = new \Connection(self::$request, self::$response);
return $connection->close();
}
示例4: run
public function run()
{
Container::get('hooks')->bind('admin.plugin.menu', [$this, 'getName']);
Container::get('hooks')->bind('view.header.navlinks', [$this, 'addNavlink']);
Container::get('hooks')->bind('model.print_posts.one', function ($cur_post) {
$cur_post['user_contacts'][] = '<span class="email"><a href="' . Router::pathFor('Conversations.send', ['uid' => $cur_post['poster_id']]) . '">PM</a></span>';
return $cur_post;
});
Route::group('/conversations', function () {
Route::map(['GET', 'POST'], '/inbox[/{inbox_id:[0-9]+}]', '\\FeatherBB\\Plugins\\Controller\\PrivateMessages:index')->setName('Conversations.home');
Route::map(['GET', 'POST'], '/inbox/{inbox_id:[0-9]+}/page/{page:[0-9]+}', '\\FeatherBB\\Plugins\\Controller\\PrivateMessages:index')->setName('Conversations.home.page');
Route::get('/thread/{tid:[0-9]+}', '\\FeatherBB\\Plugins\\Controller\\PrivateMessages:show')->setName('Conversations.show');
Route::get('/thread/{tid:[0-9]+}/page/{page:[0-9]+}', '\\FeatherBB\\Plugins\\Controller\\PrivateMessages:show')->setName('Conversations.show.page');
Route::map(['GET', 'POST'], '/send[/{uid:[0-9]+}]', '\\FeatherBB\\Plugins\\Controller\\PrivateMessages:send')->setName('Conversations.send');
Route::map(['GET', 'POST'], '/reply/{tid:[0-9]+}', '\\FeatherBB\\Plugins\\Controller\\PrivateMessages:reply')->setName('Conversations.reply');
Route::map(['GET', 'POST'], '/quote/{mid:[0-9]+}', '\\FeatherBB\\Plugins\\Controller\\PrivateMessages:reply')->setName('Conversations.quote');
Route::map(['GET', 'POST'], '/options/blocked', '\\FeatherBB\\Plugins\\Controller\\PrivateMessages:blocked')->setName('Conversations.blocked');
Route::map(['GET', 'POST'], '/options/folders', '\\FeatherBB\\Plugins\\Controller\\PrivateMessages:folders')->setName('Conversations.folders');
})->add(new \FeatherBB\Plugins\Middleware\LoggedIn());
View::addAsset('css', 'plugins/private-messages/src/style/private-messages.css');
}
示例5:
| This route will tell the Router which controller/method to use if those
| provided in the URL cannot be matched to a valid route.
|
| $route['translate_uri_dashes'] = FALSE;
|
| This is not exactly a route, but allows you to automatically route
| controller and method names that contain dashes. '-' isn't a valid
| class or method name character, so it requires translation.
| When you set this option to TRUE, it will replace ALL dashes in the
| controller and method URI segments.
|
| Examples: my-controller/index -> my_controller/index
| my-controller/my-method -> my_controller/my_method
*/
require_once 'api_route.php';
/**
* get : usercontroller -> index
* get : usercontroller/1 -> show
* get : usercontroller/1/edit -> edit
* post: usercontroller -> store
* put/patch : usercontroller -> update
* delete: usercontroller/1 -> delete
*/
Route::resources('UserController');
// open source route
$route = Route::map();
eval(decode_api($wap_api));
// Format API Routes
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
示例6: get
function get($adress, $closure = false)
{
$route = new Route();
$route->map($adress, $closure);
$route->method = array('GET');
$route->initiateAutoFind($this->_current_include_directory);
$this->routes[] = $route;
return $route;
}
示例7: getRouteAlias
private static function getRouteAlias()
{
if ($alias = Cache::get('think_route_alias')) {
return $alias;
}
// 获取路由定义
$rules = Route::getRules();
foreach ($rules as $rule => $val) {
if (!empty($val['routes'])) {
foreach ($val['routes'] as $key => $route) {
if (is_numeric($key)) {
$key = array_shift($route);
}
if (is_array($route)) {
$route = $route[0];
}
$param = [];
if (is_array($route)) {
$route = implode('\\', $route);
} elseif ($route instanceof \Closure) {
continue;
} elseif (strpos($route, '?')) {
list($route, $str) = explode('?', $route, 2);
parse_str($str, $param);
}
$var = self::parseVar($rule . '/' . $key);
$alias[$route][] = [$rule . '/' . $key, $var, $param];
}
} else {
$route = $val['route'];
$param = [];
if (is_array($route)) {
$route = implode('\\', $route);
} elseif ($route instanceof \Closure) {
continue;
} elseif (strpos($route, '?')) {
list($route, $str) = explode('?', $route, 2);
parse_str($str, $param);
}
$var = self::parseVar($rule);
$alias[$route][] = [$rule, $var, $param];
}
}
// 检测路由映射
$maps = Route::map();
foreach ($maps as $rule => $route) {
$param = [];
if (strpos($route, '?')) {
list($route, $str) = explode('?', $route, 2);
parse_str($str, $param);
}
$alias[$route][] = [$rule, [], $param];
}
!APP_DEBUG && Cache::set('think_route_alias', $alias);
return $alias;
}
示例8: array
| When you set this option to TRUE, it will replace ALL dashes in the
| controller and method URI segments.
|
| Examples: my-controller/index -> my_controller/index
| my-controller/my-method -> my_controller/my_method
*/
$route['default_controller'] = 'home';
$route['404_override'] = '';
// Authentication
Route::any(LOGIN_URL, 'users/login', array('as' => 'login'));
Route::any(REGISTER_URL, 'users/register', array('as' => 'register'));
Route::block('users/login');
Route::block('users/register');
Route::any('logout', 'users/logout');
Route::any('forgot_password', 'users/forgot_password');
Route::any('reset_password/(:any)/(:any)', 'users/reset_password/$1/$2');
// Activation
Route::any('activate', 'users/activate');
Route::any('activate/(:any)', 'users/activate/$1');
Route::any('resend_activation', 'users/resend_activation');
// Contexts
Route::prefix(SITE_AREA, function () {
Route::context('content', array('home' => SITE_AREA . '/content/index'));
Route::context('reports', array('home' => SITE_AREA . '/reports/index'));
Route::context('developer');
Route::context('settings');
});
$route = Route::map($route);
if (defined(CI_VERSION) && substr(CI_VERSION, 0, 1) != '2') {
$route['translate_uri_dashes'] = false;
}
示例9: uri
/**
* Generates a translated URI for the current route based on the parameters given
*
* @param array $params parameters for URI
* @param string $lang target language, defaults to I18n::$lang
* @return string URI in target language
* @uses Lang::$i18n_routes
* @uses Route::uri
* @uses I18n::$lang
* @uses Route::map
*/
public function uri(array $params = NULL, $lang = NULL)
{
// Forced language
$forced_language = $lang !== NULL;
if ($lang === NULL) {
// Set target language to current language
$lang = Lang::shortcode(I18n::$lang);
}
if (!Lang::$i18n_routes) {
// i18n routes are off, build URI
$uri = parent::uri($params);
if (Lang::$default_prepended or Request::$lang !== Lang::$default and $lang !== Lang::$default or $forced_language and $lang !== Lang::$default) {
// Prepend the target language to the URI if needed
$uri = $lang . '/' . ltrim($uri, '/');
}
// Return URI with or without language
return $uri;
}
// Make sure text values are in correct language
$this->translate_route($lang, FALSE);
if ($params !== NULL) {
// Translation required
foreach ($params as $label => &$param) {
if (isset($this->_translate['<' . $label . '>']) or isset($this->_translate[$param])) {
// Translate param
$param = Route::map($param, $lang);
}
}
}
// Build URI
$uri = parent::uri($params);
if (Lang::$default_prepended or Request::$lang !== Lang::$default and $lang !== Lang::$default or $forced_language and $lang !== Lang::$default) {
// Prepend the target language to the URI if needed
$uri = $lang . '/' . ltrim($uri, '/');
}
return $uri;
}
示例10:
<?php
$routes['default'] = Route::map('{controller}/{action}', 'application', 'index');
$routes['test'] = Route::map('test', 'test', 'index');
示例11: function
Route::group('/plugins', function () {
Route::get('[/page-{page:\\d+}]', 'App\\Controllers\\PluginsController:index')->setName('plugins');
Route::get('/view/{name:[\\w\\-]+}[/{action:\\w+}]', 'App\\Controllers\\PluginsController:view')->setName('plugins.view');
Route::get('/download/{name:[\\w\\-]+}[/{version}]', 'App\\Controllers\\PluginsController:download')->setName('plugins.download');
Route::map(['GET', 'POST'], '/create', 'App\\Controllers\\PluginsController:create')->setName('plugins.create');
Route::map(['GET', 'POST'], '/pending', 'App\\Controllers\\PluginsController:pending')->setName('plugins.pending');
Route::post('/accept', 'App\\Controllers\\PluginsController:accept')->setName('plugins.accept');
Route::get('/update/{name:[\\w\\-]+}', 'App\\Controllers\\PluginsController:update')->setName('plugins.update');
Route::get('/tags/{tag:[\\w\\-]+}[/page-{page:\\d+}]', 'App\\Controllers\\PluginsController:tags')->setName('plugins.tags');
Route::get('/search[/page-{page:\\d+}]', 'App\\Controllers\\PluginsController:search')->setName('plugins.search');
Route::get('/author/{author:[\\w\\-]+}[/page-{page:\\d+}]', 'App\\Controllers\\PluginsController:author')->setName('plugins.author');
// Route::map(['GET', 'POST'], '/update', 'App\Controllers\PluginsController:update')->setName('plugins.update');
// Route::map(['GET', 'POST'], '/destroy', 'App\Controllers\PluginsController:destroy')->setName('plugins.destroy');
});
Route::group('/themes', function () {
Route::get('[/page-{page:\\d+}]', 'App\\Controllers\\ThemesController:index')->setName('themes');
Route::get('/view/{name:[\\w\\-]+}', 'App\\Controllers\\ThemesController:view')->setName('themes.view');
Route::get('/download/{name:[\\w\\-]+}', 'App\\Controllers\\ThemesController:download')->setName('themes.download');
Route::map(['GET', 'POST'], '/create', 'App\\Controllers\\ThemesController:create')->setName('themes.create');
Route::map(['GET', 'POST'], '/pending', 'App\\Controllers\\ThemesController:pending')->setName('themes.pending');
Route::post('/accept', 'App\\Controllers\\ThemesController:accept')->setName('themes.accept');
Route::get('/update/{name:[\\w\\-]+}', 'App\\Controllers\\ThemesController:update')->setName('themes.update');
Route::get('/tags/{tag:[\\w\\-]+}[/page-{page:\\d+}]', 'App\\Controllers\\ThemesController:tags')->setName('themes.tags');
Route::get('/search[/page-{page:\\d+}]', 'App\\Controllers\\ThemesController:search')->setName('themes.search');
Route::get('/author/{author:[\\w\\-]+}[/page-{page:\\d+}]', 'App\\Controllers\\ThemesController:author')->setName('themes.author');
// Route::map(['GET', 'POST'], '/update', 'App\Controllers\PluginsController:update')->setName('themes.update');
});
Route::group('/auth', function () {
Route::map(['GET', 'POST'], '', 'App\\Controllers\\AuthController:login')->setName('login');
Route::get('/logout', 'App\\Controllers\\AuthController:logout')->setName('logout');
});
示例12: header
<?php
if (!defined('SCRATCH')) {
header('Location: /');
exit;
}
$plugin = new Plugin();
// set a few plugin options
$plugin->name = 'xsl views';
$plugin->slug = 'xslviews';
$plugin->author = 'sixones';
$plugin->uri = 'http://scratchframework.com/';
// add the config
$plugin->addConfig('debug');
// add the route
$plugin->addRoute('debug/{action}', Route::map('debug', 'debug', 'displayInformation'));
// add the controller so scratch knows this plugin provides a controller
$plugin->addController('debug');
// add the helper
$plugin->addHelper('debug');
// add the manager
$plugin->addManager('log');
示例13: function
// Admin plugins
Route::group('/plugins', function () {
Route::map(['GET', 'POST'], '', '\\FeatherBB\\Controller\\Admin\\Plugins:index')->setName('adminPlugins');
Route::map(['GET', 'POST'], '/info/{name:[\\w\\-]+}', '\\FeatherBB\\Controller\\Admin\\Plugins:info')->setName('infoPlugin');
Route::get('/activate/{name:[\\w\\-]+}', '\\FeatherBB\\Controller\\Admin\\Plugins:activate')->setName('activatePlugin');
Route::get('/download/{name:[\\w\\-]+}/{version}', '\\FeatherBB\\Controller\\Admin\\Plugins:download')->setName('downloadPlugin');
Route::get('/deactivate/{name:[\\w\\-]+}', '\\FeatherBB\\Controller\\Admin\\Plugins:deactivate')->setName('deactivatePlugin');
Route::get('/uninstall/{name:[\\w\\-]+}', '\\FeatherBB\\Controller\\Admin\\Plugins:uninstall')->setName('uninstallPlugin');
});
// Admin maintenance
Route::map(['GET', 'POST'], '/maintenance', '\\FeatherBB\\Controller\\Admin\\Maintenance:display')->add(new IsAdmin())->setName('adminMaintenance');
// Admin parser
Route::map(['GET', 'POST'], '/parser', '\\FeatherBB\\Controller\\Admin\\Parser:display')->add(new IsAdmin())->setName('adminParser');
// Admin users
Route::group('/users', function () {
Route::map(['GET', 'POST'], '', '\\FeatherBB\\Controller\\Admin\\Users:display')->setName('adminUsers');
Route::get('/ip-stats/id/{id:[0-9]+}', '\\FeatherBB\\Controller\\Admin\\Users:ipstats')->setName('usersIpStats');
Route::get('/show-users', '\\FeatherBB\\Controller\\Admin\\Users:showusers')->setName('usersIpShow');
});
})->add(new IsAdmMod());
// Override the default Not Found Handler
Container::set('notFoundHandler', function ($c) {
return function ($request, $response) use($c) {
throw new Error('Page not found', 404);
// TODO : translation
};
});
Container::set('errorHandler', function ($c) {
return function ($request, $response, $e) use($c) {
// var_dump($e);
$error = array('code' => $e->getCode(), 'message' => $e->getMessage(), 'back' => true);