本文整理汇总了PHP中lithium\net\http\Router类的典型用法代码示例。如果您正苦于以下问题:PHP Router类的具体用法?PHP Router怎么用?PHP Router使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Router类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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('/<foo>/<bar>', $this->subject->url('/<foo>/<bar>'));
$result = $this->subject->url(array('Controller::action', 'id' => '<script />'));
$this->assertEqual('/controller/action/<script />', $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
示例16:
* the primary key of the database object, and can be accessed in the controller as
* `$this->request->id`.
*
* If you're using a relational database, such as MySQL, SQLite or Postgres, where the primary key
* is an integer, uncomment the routes below to enable URLs like `/posts/edit/1138`,
* `/posts/view/1138.json`, etc.
*/
// Router::connect('/{:controller}/{:action}/{:id:\d+}.{:type}', array('id' => null));
// Router::connect('/{:controller}/{:action}/{:id:\d+}');
/**
* If you're using a document-oriented database, such as CouchDB or MongoDB, or another type of
* database which uses 24-character hexidecimal values as primary keys, uncomment the routes below.
*/
// Router::connect('/{:controller}/{:action}/{:id:[0-9a-f]{24}}.{:type}', array('id' => null));
// Router::connect('/{:controller}/{:action}/{:id:[0-9a-f]{24}}');
/**
* ### Default controller/action routes
*
* Finally, connect the default route. This route acts as a catch-all, intercepting requests in the
* following forms:
*
* - `/foo/bar`: Routes to `FooController::bar()` with no parameters passed.
* - `/foo/bar/param1/param2`: Routes to `FooController::bar('param1, 'param2')`.
* - `/foo`: Routes to `FooController::index()`, since `'index'` is assumed to be the action if none
* is otherwise specified.
*
* In almost all cases, custom routes should be added above this one, since route-matching works in
* a top-down fashion.
*/
Router::connect('/{:controller}/{:action}/{:args}');
开发者ID:unionofrad,项目名称:framework,代码行数:30,代码来源:routes.php
示例17: 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);
}
开发者ID:rapzo,项目名称:lithium,代码行数:10,代码来源:RouterTest.php
示例18: requestPasswordReset
/**
* Logic to request password reset for user
*
* @param array $conditions
* @return int
*/
public static function requestPasswordReset(array $conditions = array())
{
$self = static::_object();
if ($user = $self::first(compact('conditions'))) {
$time = new \DateTime();
$reset = PasswordResets::first(array('conditions' => array('user_id' => $user->id)));
if ($reset) {
$expires = new \DateTime($reset->expires);
if ($expires <= $time) {
$reset->delete();
} else {
return PasswordResets::RESET_TOKEN_EXISTS;
}
}
if (!$reset || !$reset->exists()) {
$expires = clone $time;
$expires->modify(LI3_UM_PasswordResetExpires);
$token = Token::generate($user->email);
$reset = PasswordResets::create(array('user_id' => $user->id, 'expires' => $expires->format('Y-m-d H:i:s'), 'token' => $token));
if ($reset->save()) {
$link = Router::match(array('li3_usermanager.Users::resetPassword', 'id' => $user->id, 'token' => $token), $self::$request, array('absolute' => true));
Mailer::$_data['subject'] = 'Your password reset link!';
Mailer::$_data['from'] = LI3_UM_PasswordResetEmailFrom;
Mailer::$_data['to'] = $user->email;
Mailer::$_data['body'] = 'This is your password reset link:' . "\n" . $link;
return PasswordResets::GENERATED_NEW_RESET_TOKEN;
}
}
}
}
开发者ID:djordje,项目名称:li3_usermanager,代码行数:36,代码来源:Users.php
示例19: testRouteLoading
/**
* Test if the routes.php file is loaded correctly and the
* routes are connected to the router.
*/
public function testRouteLoading()
{
$this->assertEmpty(Router::get(null, true));
$command = new Route(array('routes' => $this->_config['routes']));
$this->assertCount(4, Router::get(null, true));
Router::reset();
$request = new Request();
$request->params['env'] = 'production';
$command = new Route(compact('request') + array('routes' => $this->_config['routes']));
$this->assertCount(2, Router::get(null, true));
}
开发者ID:unionofrad,项目名称:lithium,代码行数:15,代码来源:RouteTest.php
示例20: 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())));
开发者ID:bruensicke,项目名称:radium,代码行数:20,代码来源:view.audio.html.php
注:本文中的lithium\net\http\Router类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论