本文整理汇总了PHP中lithium\net\http\Router::match方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::match方法的具体用法?PHP Router::match怎么用?PHP Router::match使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lithium\net\http\Router
的用法示例。
在下文中一共展示了Router::match方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: nav
/**
* Create navigation link compatible with `Twitter Bootstrap` markup.
* Instead of plain `<a/>` output this method wrap anchor in `<li/>`. If current url is url of
* wrapped `<a/>` add `active` class to `<li/>` wrapper.
* For example:
* {{{
* $this->backend->nav('Test', '/');
* // outputs:
* // <li><a href="/">Test</a></li>
* // if current url is url of anchor:
* // <li class="active"><a href="/">Test</a></li>
* }}}
*
* @param $title
* @param mixed $url
* @param array $options Add following options to link:
* - `'wrapper-options'` _array_: Options that will be passed to `'nav-link'`
* - `'return'` _string_: Define would you like `'html'` output or `'array'` that contains two
* keys `'active'` _boolean_ and `'html'` used by `dropdown` method for example to know when
* to add `'active'` class to parent.
*
* @return array|string
*
* @see lithium\template\helper\Html::link()
*/
public function nav($title, $url = null, array $options = array())
{
$defaults = array('wrapper-options' => array(), 'return' => 'html');
list($scope, $options) = $this->_options($defaults, $options);
$request = $this->_context->request();
$currentUrl = $request->env('base') . $request->url;
$matchedUrl = Router::match($url, $request);
$active = false;
if ($currentUrl === $matchedUrl || $currentUrl === $matchedUrl . '/index') {
$active = true;
if (isset($scope['wrapper-options']['class'])) {
$scope['wrapper-options']['class'] .= ' active';
} else {
$scope['wrapper-options']['class'] = 'active';
}
}
$link = $this->link($title, $url, $options);
$html = $this->_render(__METHOD__, 'nav-link', array('options' => $scope['wrapper-options'], 'link' => $link));
if ($scope['return'] === 'html') {
return $html;
}
if ($scope['return'] === 'array') {
return compact('active', 'html');
}
}
示例2: index
/**
* Fetch data for current path
* On first access return HTML
* Next time you fetch via AJAX return just JSON that we render client side
*
* html:method GET
*/
public function index()
{
$path = $this->request->args ? join('/', $this->request->args) : null;
$data = Location::ls($path);
if ($data === false) {
return $this->redirect($this->_link);
}
$breadcrumb = array(array('Index', 'url' => Router::match($this->_link, $this->request, array('absolute' => true))));
$args = array();
foreach ($this->request->args as $arg) {
$args[] = $arg;
$this->_link += array('args' => $args);
$breadcrumb[] = array($arg, 'url' => Router::match($this->_link, $this->request, array('absolute' => true)));
}
$breadcrumb[count($breadcrumb) - 1]['url'] = null;
if ($this->request->is('ajax')) {
return $this->render(array('json' => compact('data', 'breadcrumb')));
}
return compact('data', 'breadcrumb');
}
示例3: _prepare
/**
* Prepare data to display and calculate the current node.
* @param array $menu The menu description.
* @param array $options Options.
* @return array Calulated menu.
*/
protected function _prepare(array $menu, array $options = array())
{
$return = array();
$active = false;
$current = array_filter($this->request->params);
foreach ($menu as $label => $mask) {
$link = array('url' => null, 'label' => is_string($label) ? $label : null, 'class' => null, 'active' => null, 'mask' => null);
if (is_string($mask)) {
$link['url'] = $mask;
} elseif (array_intersect_key($mask, array('class' => true))) {
$link = $mask + $link;
} else {
$link['url'] = $mask;
}
if (!is_string($link['url'])) {
$link['url'] = Router::match($link['url']);
}
if (!$active) {
if ($link['active']) {
// Force the value
$link['active'] = 'active';
} else {
if ($link['mask']) {
// We have a mask. Easy.
$compare = array_filter($link['mask']);
} else {
// Only do this if we haven't found any active link yet and we haven't any mask to compare !
$request = new Request();
$request->url = $link['url'];
$compare = array_filter(Router::parse($request)->params);
}
$link['active'] = Url::match($current, $compare) ? 'active' : '';
}
$active = !empty($link['active']);
}
$return[] = $link;
}
return $return;
}
示例4: upload
public function upload()
{
if (!$this->request->is('ajax')) {
return array();
}
$model = $this->model;
$this->_render['type'] = 'json';
$allowed = '*';
$file = $this->_upload(compact('allowed'));
if ($file['error'] !== UPLOAD_ERR_OK) {
return $file;
}
$result = $model::init($file);
if (!empty($result['asset'])) {
$result['message'] = !empty($result['success']) ? 'upload successful' : 'file already present';
$result['url'] = Router::match(array('library' => 'radium', 'controller' => 'assets', 'action' => 'view', 'id' => $result['asset']->id()), $this->request, array('absolute' => true));
// unset($result['asset']);
}
// if ($result['success']) {
// unset($result['asset']);
// }
return $result;
}
示例5: addAction
public function addAction()
{
$success = false;
$url = "";
$errors = array();
if (!Auth::check('default')) {
$errors['login'] = 'You need to be logged.';
} else {
if (!$this->request->is('post')) {
$errors['call'] = 'This action can only be called with post';
} else {
if ($this->request->data) {
$post = Posts::create($this->request->data);
if ($success = $post->save()) {
$url = "http://" . $_SERVER['HTTP_HOST'] . Router::match(array('controller' => 'posts', 'action' => 'view', 'id' => $post->id));
} else {
$errors = $post->errors();
}
}
}
}
return compact('success', 'errors', 'url');
}
示例6: generate
/**
* Renders and returns the generated html for the targeted item and its element and children
*
* @param mixed $source String or Array target notations
* @param array $options
* @options 'class' > <ul class="?"><li><ul>..</li></ul>
* @options 'id' > <ul id="?"><li><ul>..</li></ul>
* @options 'ul' > string:class || array('class','style')
* @options 'div' > string:class || boolean:use || array('id','class','style')
* @options 'active'> array('tag' => string(span,strong,etc), 'attributes' => array(htmlAttributes), 'strict' => boolean(true|false)))
*
* @example echo $menu->generate('context', array('active' => array('tag' => 'link','attributes' => array('style' => 'color:red;','id'=>'current'))));
* @return mixed string generated html or false if target doesnt exist
*/
function generate($source = 'main', $options = array()) {
$out = '';
$list = '';
if (isset($options['ul']))
$ulAttributes = $options['ul'];
else
$ulAttributes = array();
// DOM class attribute for outer UL
if (isset($options['class'])) {
$ulAttributes['class'] = $options['class'];
} else {
if (is_array($source)) {
$ulAttributes['class'] = 'menu_' . $source[count($source) - 1];
} else {
$ulAttributes['class'] = 'menu_' . $source;
}
}
// DOM element id for outer UL
if (isset($options['id'])) {
$ulAttributes['id'] = $options['id'];
}
$menu = array();
// Find source menu
if (is_array($source)) {
$depth = count($source);
$menu = &$this->items;
for ($i = 0; $i < $depth; $i++) {
if (!empty($menu) && array_key_exists($source[$i], $menu)) {
$menu = &$menu[$source[$i]];
} else {
if (!isset($options['force']) || (isset($options['force']) && !$options['force']))
return false;
}
}
} else {
if (!isset($this->items[$source])) {
if (!isset($options['force']) || (isset($options['force']) && !$options['force']))
return false;
} else {
$menu = &$this->items[$source];
}
}
if (isset($options['reverse']) && $options['reverse'] == true) {
unset($options['reverse']);
$menu = array_reverse($menu);
}
$requestObj = $this->_context->request();
if (isset($options['active']['strict']) && !$options['active']['strict']) {
$requestParams = $requestObj->params;
$here = trim(Router::match(array(
'controller' => $requestParams['controller'],
'action' => $requestParams['action']
), $requestObj), "/");
} else {
$here = $requestObj->url;
}
// Generate menu items
foreach ($menu as $key => $item) {
$liAttributes = array();
$aAttributes = array();
if (isset($item[1]['li'])) {
$liAttributes = $item[1]['li'];
}
if (isset($item[0]) && $item[0] === true) {
$menusource = $source;
if (!is_array($menusource)) {
$menusource = array($menusource);
}
$menusource[] = $key;
// Don't set DOM element id on sub menus */
if (isset($options['id'])) {
unset($options['id']);
}
//.........这里部分代码省略.........
示例7: _url
/**
* Generates the url
*
* @param array $params Query params to force
* @return string Full url
*/
protected function _url(array $params = [])
{
$current = !empty($this->_request->params) ? $this->_request->params : [];
$query = !empty($this->_request->query) ? $this->_request->query : [];
if (!empty($query['url'])) {
unset($query['url']);
}
$query = $params + $query;
return Router::match(!empty($query) ? ['?' => $query] + $current : $current, $this->_request, ['absolute' => true]);
}
示例8: foreach
$cacheKey = $params['request']->params['controller'] . 'Controller::' . $params['request']->params['action'];
if (isset($response->varnish) && !empty($response->varnish)) {
$cache = Varnish::cache($cacheKey, true);
if (is_array($response->varnish)) {
$cache += $response->varnish;
}
} else {
$cache = Varnish::cache($cacheKey);
}
if (!empty($cache)) {
$varnishHeaders = Varnish::headers($cache);
foreach ($varnishHeaders as $key => $val) {
$response->headers($key, $val);
}
}
return $response;
});
// filter to set esi includes around partials
Media::applyFilter('view', function ($self, $params, $chain) {
$view = $chain->next($self, $params, $chain);
$view->applyFilter('_step', function ($self, $params, $chain) {
$content = $chain->next($self, $params, $chain);
if (isset($params['options']['esi']) && $params['options']['esi'] == true) {
if (!empty($content)) {
$content = \lithium\util\String::insert(Varnish::config('template'), array('url' => Router::match(array('controller' => 'Esi', 'action' => 'show', 'type' => $params['step']['path'], 'name' => $params['options']['template'])), 'content' => $content));
}
}
return $content;
});
return $view;
});
示例9: array
<?php
use lithium\net\http\Router;
$url = Router::match(array('library' => 'radium', 'controller' => 'assets', 'action' => 'show', 'id' => $this->scaffold->object->id()), $this->request(), array('absolute' => true));
?>
<div class="plaintext"><pre><?php
echo $url;
?>
</pre></div>
<audio controls><source src="<?php
echo $url;
?>
" type="<?php
echo $this->scaffold->object['mime'];
?>
"></audio>
<hr />
<?php
unset($this->scaffold->object['file']);
echo $this->scaffold->render('data', array('data' => \lithium\util\Set::flatten($this->scaffold->object->data())));
示例10: _url
/**
* Generates absolute URL to the webroot folder via reverse routing.
*
* @return string Absolute URL to webroot
*/
protected static function _url()
{
$request = new Request();
return Router::match('/', $request, ['absolute' => true]);
}
示例11: numbers
/**
* Creates the individual numeric page links, with the current link in the middle.
*
* @see li3_paginate\extensions\helper\Paginator::paginate()
* @return string Markup of the numeric page links.
*/
public function numbers(array $options = array())
{
if (!empty($options)) {
$this->config($options);
}
$maxNumbers = $this->_config['maxNumbers'];
$addOne = false;
if ($maxNumbers % 2 > 0) {
$addOne = true;
$maxNumbers--;
}
$minNumbersBefore = $maxNumbers / 2;
$maxNumbersAfter = $minNumbersBefore;
if ($addOne) {
$maxNumbers++;
}
$start = $this->_page - $minNumbersBefore;
$end = ceil($this->_total / $this->_limit);
if ($this->_page <= $minNumbersBefore) {
$start = 1;
}
if ($this->_page + $maxNumbersAfter < $end) {
$end = $this->_page + $maxNumbersAfter;
}
$buffer = "";
$url = array('controller' => $this->_controller, 'action' => $this->_action);
true;
if (!empty($this->_library)) {
$url['library'] = $this->_library;
}
for ($i = $start; $i <= $end; $i++) {
$config = array('page' => $i) + $this->_query();
$url = \lithium\net\http\Router::match($config + $this->_context->_config['request']->params, $this->_context->_config['request'], array('absolute' => true));
if ($this->_page == $i) {
$buffer .= $this->_config['activeOpenTag'] . $this->_context->html->link($i, $url) . $this->_config['closeTag'];
} else {
$buffer .= $this->_config['openTag'] . $this->_context->html->link($i, $url) . $this->_config['closeTag'];
}
}
return $buffer;
}
示例12: testLibraryBasedRoute
public function testLibraryBasedRoute()
{
$route = Router::connect('/{:library}/{:controller}/{:action}', array('library' => 'app'), array('persist' => array('library')));
$expected = '/app/hello/world';
$result = Router::match(array('controller' => 'hello', 'action' => 'world'));
$this->assertEqual($expected, $result);
$expected = '/myapp/hello/world';
$result = Router::match(array('library' => 'myapp', 'controller' => 'hello', 'action' => 'world'));
$this->assertEqual($expected, $result);
}
示例13: function
Dispatcher::applyFilter('_callable', function ($self, $params, $chain) {
// Run other filters first. This allows this one to not exactly be overwritten or excluded...But it does allow for a different login action to be used...
// TODO: Perhaps allow this to be skipped...
$next = $chain->next($self, $params, $chain);
$request = $params['request'];
$action = $request->action;
$user = Auth::check('li3b_user');
// Protect all admin methods except for login and logout.
if ($request->admin === true && $action != 'login' && $action != 'logout') {
$action_access = Access::check('default', $user, $request, array('rules' => array('allowManagers')));
if (!empty($action_access)) {
FlashMessage::write($action_access['message'], 'default');
if ($user) {
header('Location: ' . Router::match($action_access['redirect']));
} else {
header('Location: ' . Router::match(array('library' => 'li3b_users', 'controller' => 'users', 'action' => 'login')));
}
// None shall pass.
exit;
}
}
// Sets the current user in each request for convenience.
$params['request']->user = $user;
return $next;
// return $chain->next($self, $params, $chain);
});
Access::config(array('default' => array('adapter' => 'Rules', 'filters' => array())));
// Set some basic rules to be used from anywhere
// Allow access for users with a role of "administrator" or "content_editor"
Access::adapter('default')->add('allowManagers', function ($user, $request, $options) {
if ($user && ($user['role'] == 'administrator' || $user['role'] == 'content_editor')) {
示例14: _init
/**
* _init()
*
* Setup the php library
*/
public function _init()
{
parent::_init();
//var_dump(getBaseUrl());
static::$_uploadHandler = new UploadHandler(array('script_url' => Router::match(array('Uploads::deleteAction', 'type' => 'json')), 'upload_dir' => LITHIUM_APP_PATH . '/webroot/upload/files/', 'upload_url' => '/upload/files/', 'param_name' => 'files', 'delete_type' => 'DELETE', 'max_file_size' => null, 'min_file_size' => 1, 'accept_file_types' => '/.+$/i', 'max_number_of_files' => null, 'max_width' => null, 'max_height' => null, 'min_width' => 1, 'min_height' => 1, 'discard_aborted_uploads' => true, 'orient_image' => false, 'image_versions' => array('thumbnail' => array('upload_dir' => LITHIUM_APP_PATH . '/webroot/upload/thumbnails/', 'upload_url' => '/upload/thumbnails/', 'max_width' => 80, 'max_height' => 80))));
}
示例15: testScopeBase
public function testScopeBase()
{
$request = new Request(array('base' => 'lithium/app'));
Router::connect('/{:controller}/{:action}');
$url = array('controller' => 'HelloWorld');
$expected = '/lithium/app/hello_world';
$this->assertEqual($expected, Router::match($url, $request));
Router::attach(false, array('base' => 'lithium'));
$expected = '/lithium/hello_world';
$this->assertEqual($expected, Router::match($url, $request));
Router::attach(false, array('base' => ''));
$expected = '/hello_world';
$this->assertEqual($expected, Router::match($url, $request));
}