当前位置: 首页>>代码示例>>PHP>>正文


PHP http\Router类代码示例

本文整理汇总了PHP中lithium\net\http\Router的典型用法代码示例。如果您正苦于以下问题:PHP Router类的具体用法?PHP Router怎么用?PHP Router使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Router类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: tearDown

 public function tearDown()
 {
     Router::reset();
     foreach ($this->_routes as $route) {
         Router::connect($route);
     }
 }
开发者ID:EHER,项目名称:monopolis,代码行数:7,代码来源:RendererTest.php

示例2: 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');
     }
 }
开发者ID:djordje,项目名称:li3_backend,代码行数:50,代码来源:Backend.php

示例3: match

 /**
  * Compare $url with $mask. Returns true if there is a match !
  *
  * @param  mixed $url   String, array or Request : url to test
  * @param  array  $mask Mask, in a Request::$params form
  * @return bool         Yep/nope ?
  */
 public static function match($url, array $mask)
 {
     // Multiple $url types
     if ($url instanceof Request) {
         $test = Router::parse($url);
     } elseif (is_string($url)) {
         $request = new Request();
         $request->url = $url;
         $test = Router::parse($request);
     } else {
         $test = $url;
     }
     foreach ($mask as $key => $value) {
         if (!isset($test[$key])) {
             return false;
         }
         if (is_array($value) && !static::match($mask[$key], $test[$key])) {
             return false;
         }
         if (is_string($value) && strtolower($value) !== strtolower($test[$key])) {
             return false;
         }
     }
     return true;
 }
开发者ID:scharrier,项目名称:li3_menu,代码行数:32,代码来源:Url.php

示例4: teardown

 function teardown()
 {
     Router::reset();
     foreach ($this->_routes as $route) {
         Router::connect($route);
     }
     unset($this->analytics);
 }
开发者ID:joseym,项目名称:li3_analytics,代码行数:8,代码来源:AnalyticsTest.php

示例5: tearDown

 /**
  * Clean up after the test.
  *
  * @return void
  */
 public function tearDown()
 {
     Router::connect(null);
     $this->_routes->each(function ($route) {
         Router::connect($route);
     });
     unset($this->html);
 }
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:13,代码来源:HtmlTest.php

示例6: setUp

 public function setUp()
 {
     $this->html = new Html();
     $this->mock = new MockHtml();
     Router::connect('/test/{:args}', array('controller' => '\\lithium\\test\\Controller'));
     Router::connect('/test', array('controller' => '\\lithium\\test\\Controller'));
     $this->request = new Request(array('base' => null, 'env' => array('PHP_SELF' => '/', 'DOCUMENT_ROOT' => '/')));
 }
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:8,代码来源:HtmlTest.php

示例7: testRun

 public function testRun()
 {
     Router::connect('/', array('controller' => 'test', 'action' => 'test'));
     $request = new Request();
     $request->url = '/';
     MockDispatcher::run($request);
     $result = end(MockDispatcher::$dispatched);
     $expected = array('controller' => 'test', 'action' => 'test');
     $this->assertEqual($expected, $result->params);
 }
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:10,代码来源:DispatcherTest.php

示例8: setUp

 public function setUp()
 {
     $this->_routes = Router::get();
     Router::reset();
     Router::connect('/{:controller}/{:action}/page/{:page:[0-9]+}');
     $request = new Request();
     $request->params = array('controller' => 'posts', 'action' => 'index');
     $request->persist = array('controller');
     $this->context = new MockRenderer(compact('request'));
     $this->pagination = new Pagination(array('context' => $this->context));
 }
开发者ID:thedisco,项目名称:li3_pagination,代码行数:11,代码来源:PaginationTest.php

示例9: tearDown

 /**
  * Clean up after the test.
  */
 public function tearDown()
 {
     Router::reset();
     foreach ($this->_routes as $scope => $routes) {
         Router::scope($scope, function () use($routes) {
             foreach ($routes as $route) {
                 Router::connect($route);
             }
         });
     }
     unset($this->html);
 }
开发者ID:nilamdoc,项目名称:KYCGlobal,代码行数:15,代码来源:HtmlTest.php

示例10: testConfigManipulation

 public function testConfigManipulation()
 {
     $config = MockDispatcher::config();
     $expected = array('rules' => array());
     $this->assertEqual($expected, $config);
     MockDispatcher::config(array('rules' => array('admin' => array('action' => 'admin_{:action}'))));
     Router::connect('/', array('controller' => 'test', 'action' => 'test', 'admin' => true));
     MockDispatcher::run(new Request(array('url' => '/')));
     $result = end(MockDispatcher::$dispatched);
     $expected = array('action' => 'admin_test', 'controller' => 'Test', 'admin' => true);
     $this->assertEqual($expected, $result->params);
 }
开发者ID:EHER,项目名称:monopolis,代码行数:12,代码来源:DispatcherTest.php

示例11: testUrlAutoEscaping

 /**
  * Tests that URLs are properly escaped by the URL handler.
  */
 public function testUrlAutoEscaping()
 {
     Router::connect('/{:controller}/{:action}/{:id}');
     $this->assertEqual('/<foo>/<bar>', $this->subject->url('/<foo>/<bar>'));
     $result = $this->subject->url(array('Controller::action', 'id' => '<script />'));
     $this->assertEqual('/controller/action/<script />', $result);
     $this->subject = new Simple(array('response' => new Response(), 'view' => new View(), 'request' => new Request(array('base' => '', 'env' => array('HTTP_HOST' => 'foo.local')))));
     $this->assertEqual('/&lt;foo&gt;/&lt;bar&gt;', $this->subject->url('/<foo>/<bar>'));
     $result = $this->subject->url(array('Controller::action', 'id' => '<script />'));
     $this->assertEqual('/controller/action/&lt;script /&gt;', $result);
     $result = $this->subject->url(array('Posts::index', '?' => array('foo' => 'bar', 'baz' => 'dib')));
     $this->assertEqual('/posts?foo=bar&baz=dib', $result);
 }
开发者ID:WarToaster,项目名称:HangOn,代码行数:16,代码来源:RendererTest.php

示例12: _restoreCtrlContext

 protected function _restoreCtrlContext()
 {
     Router::reset();
     foreach ($this->_context['routes'] as $scope => $routes) {
         Router::scope($scope, function () use($routes) {
             foreach ($routes as $route) {
                 Router::connect($route);
             }
         });
     }
     foreach ($this->_context['scopes'] as $scope => $attachment) {
         Router::attach($scope, $attachment);
     }
     Router::scope($this->_context['scope']);
 }
开发者ID:fedeisas,项目名称:lithium,代码行数:15,代码来源:Controller.php

示例13: 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');
 }
开发者ID:djordje,项目名称:li3_filemanager,代码行数:27,代码来源:FilesController.php

示例14: 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;
 }
开发者ID:bruensicke,项目名称:radium,代码行数:23,代码来源:AssetsController.php

示例15: testConfigManipulation

 public function testConfigManipulation()
 {
     $config = MockDispatcher::config();
     $expected = array('rules' => array());
     $this->assertEqual($expected, $config);
     MockDispatcher::config(array('rules' => array('admin' => array('action' => 'admin_{:action}'))));
     Router::connect('/', array('controller' => 'test', 'action' => 'test', 'admin' => true));
     MockDispatcher::run(new Request(array('url' => '/')));
     $result = end(MockDispatcher::$dispatched);
     $expected = array('action' => 'admin_test', 'controller' => 'Test', 'admin' => true);
     $this->assertEqual($expected, $result->params);
     MockDispatcher::config(array('rules' => array('action' => array('action' => function ($params) {
         return Inflector::camelize(strtolower($params['action']), false);
     }))));
     MockDispatcher::$dispatched = array();
     Router::reset();
     Router::connect('/', array('controller' => 'test', 'action' => 'TeST-camelize'));
     MockDispatcher::run(new Request(array('url' => '/')));
     $result = end(MockDispatcher::$dispatched);
     $expected = array('action' => 'testCamelize', 'controller' => 'Test');
     $this->assertEqual($expected, $result->params);
     MockDispatcher::config(array('rules' => function ($params) {
         if (isset($params['admin'])) {
             return array('special' => array('action' => 'special_{:action}'));
         }
         return array();
     }));
     MockDispatcher::$dispatched = array();
     Router::reset();
     Router::connect('/', array('controller' => 'test', 'action' => 'test', 'admin' => true));
     Router::connect('/special', array('controller' => 'test', 'action' => 'test', 'admin' => true, 'special' => true));
     MockDispatcher::run(new Request(array('url' => '/')));
     $result = end(MockDispatcher::$dispatched);
     $expected = array('action' => 'test', 'controller' => 'Test', 'admin' => true);
     $this->assertEqual($expected, $result->params);
     MockDispatcher::run(new Request(array('url' => '/special')));
     $result = end(MockDispatcher::$dispatched);
     $expected = array('action' => 'special_test', 'controller' => 'Test', 'admin' => true, 'special' => true);
     $this->assertEqual($expected, $result->params);
 }
开发者ID:nilamdoc,项目名称:KYCGlobal,代码行数:40,代码来源:DispatcherTest.php


注:本文中的lithium\net\http\Router类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。