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


PHP Router::normalize方法代码示例

本文整理汇总了PHP中Router::normalize方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::normalize方法的具体用法?PHP Router::normalize怎么用?PHP Router::normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Router的用法示例。


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

示例1: requestAction

 /**
  * Calls a controller's method from any location. Can be used to connect controllers together
  * or tie plugins into a main application. requestAction can be used to return rendered views
  * or fetch the return value from controller actions.
  *
  * Under the hood this method uses Router::reverse() to convert the $url parameter into a string
  * URL.  You should use URL formats that are compatible with Router::reverse()
  *
  * #### Passing POST and GET data
  *
  * POST and GET data can be simulated in requestAction.  Use `$extra['url']` for
  * GET data.  The `$extra['data']` parameter allows POST data simulation.
  *
  * @param string|array $url String or array-based url.  Unlike other url arrays in CakePHP, this
  *    url will not automatically handle passed and named arguments in the $url parameter.
  * @param array $extra if array includes the key "return" it sets the AutoRender to true.  Can
  *    also be used to submit GET/POST data, and named/passed arguments.
  * @return mixed Boolean true or false on success/failure, or contents
  *    of rendered action if 'return' is set in $extra.
  */
 public function requestAction($url, $extra = array())
 {
     if (empty($url)) {
         return false;
     }
     App::uses('Dispatcher', 'Routing');
     if (($index = array_search('return', $extra)) !== false) {
         $extra['return'] = 0;
         $extra['autoRender'] = 1;
         unset($extra[$index]);
     }
     if (is_array($url) && !isset($extra['url'])) {
         $extra['url'] = array();
     }
     $extra = array_merge(array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1), $extra);
     $data = isset($extra['data']) ? $extra['data'] : null;
     unset($extra['data']);
     if (is_string($url) && strpos($url, FULL_BASE_URL) === 0) {
         $url = Router::normalize(str_replace(FULL_BASE_URL, '', $url));
     }
     if (is_string($url)) {
         $request = new CakeRequest($url);
     } elseif (is_array($url)) {
         $params = $url + array('pass' => array(), 'named' => array(), 'base' => false);
         $params = array_merge($params, $extra);
         $request = new CakeRequest(Router::reverse($params), false);
     }
     if (isset($data)) {
         $request->data = $data;
     }
     $dispatcher = new Dispatcher();
     $result = $dispatcher->dispatch($request, new CakeResponse(), $extra);
     Router::popRequest();
     return $result;
 }
开发者ID:laiello,项目名称:double-l-bookmanagement,代码行数:55,代码来源:Object.php

示例2: beforeSave

 public function beforeSave($options = array())
 {
     if (isset($this->data[$this->alias]['url'])) {
         $url = Router::normalize($this->data[$this->alias]['url']);
         $this->data[$this->alias]['url'] = $url;
     }
     return true;
 }
开发者ID:xintesa,项目名称:seolite,代码行数:8,代码来源:SeoLiteUrl.php

示例3: error403

 /**
  * Convenience method to display a 403 page.
  *
  * @param array $params Parameters for controller
  * @access public
  */
 function error403($params)
 {
     extract($params, EXTR_OVERWRITE);
     if (!isset($url)) {
         $url = $this->controller->here;
     }
     $url = Router::normalize($url);
     $this->controller->header("HTTP/1.0 403 Forbidden");
     $this->controller->set(array('title_for_layout' => __t('Forbidden'), 'title' => __t('403 Forbidden'), 'url' => h($url)));
     $this->_outputMessage('error403');
 }
开发者ID:sandulungu,项目名称:StarLight,代码行数:17,代码来源:app_error.php

示例4: forbidden

 public function forbidden($params)
 {
     extract($params, EXTR_OVERWRITE);
     if (!isset($url)) {
         $url = $this->controller->here;
     }
     $url = Router::normalize($url);
     $this->controller->header("HTTP/1.0 403 Forbidden");
     $this->controller->set(array('code' => '403', 'name' => __('Forbidden', true), 'message' => h($url), 'base' => $this->controller->base));
     $this->_outputMessage('forbidden');
 }
开发者ID:hiromi2424,项目名称:cake_app_base,代码行数:11,代码来源:app_error.php

示例5: reverseParams

 /**
  * reverse a request from the params
  */
 public static function reverseParams($request)
 {
     // it's annoying that there's no way to get a url from params
     unset($request['alias']);
     // for backwards compatibility
     $url = $request;
     unset($url['pass']);
     $passed = implode('/', $request['pass']);
     $passed = !empty($passed) ? '/' . $passed : null;
     unset($url['named']);
     $named = str_replace(array('[]', '{"', '":"', '","', '"}'), array('', '/', ':', '/', ''), json_encode($request['named']));
     return Router::normalize(implode('/', $url) . $passed . $named);
 }
开发者ID:ayaou,项目名称:Zuha,代码行数:16,代码来源:global.php

示例6: startup

 /**
  * Allows/denies access to the action according to the permissions
  * set. It only checks wheter it's a public action or controlled
  * access action.
  * 
  * @access public
  * @param object $controller
  * @return void
  */
 function startup(&$controller)
 {
     if (isset($controller->JjAuth)) {
         $allowAccess = empty($this->thisSection['permissions']) || $controller->JjAuth->can($this->thisSection['permissions']);
         if ($allowAccess) {
             $controller->JjAuth->allow($controller->params['action']);
         } else {
             if (Router::normalize($controller->here) == Router::normalize($controller->JjAuth->loginRedirect)) {
                 $controller->JjAuth->logout();
             }
             $controller->JjAuth->deny($controller->params['action']);
         }
     }
 }
开发者ID:rcaravita,项目名称:jodeljodel,代码行数:23,代码来源:sect_section_handler.php

示例7: logout

 /**
  * Log a user out.
  *
  * Returns the logout action to redirect to. Triggers the logout() method of
  * all the authenticate objects, so they can perform custom logout logic.
  * AuthComponent will remove the session data, so there is no need to do that
  * in an authentication object. Logging out will also renew the session id.
  * This helps mitigate issues with session replays.
  *
  * @return string AuthComponent::$logoutRedirect
  * @see  AuthComponent::$logoutRedirect
  * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#logging-users-out
  */
 public function logout()
 {
     $this->_setDefaults();
     if (empty($this->_authenticateObjects)) {
         $this->constructAuthenticate();
     }
     $user = $this->user();
     foreach ($this->_authenticateObjects as $auth) {
         $auth->logout($user);
     }
     $this->Session->delete(static::$sessionKey);
     $this->Session->delete('Auth.redirect');
     $this->Session->renew();
     return Router::normalize($this->logoutRedirect);
 }
开发者ID:mrbadao,项目名称:api-official,代码行数:28,代码来源:ApiAuthComponent.php

示例8: error500

	/**
	 * Convenience method to display a 500 page.
	 *
	 * @param array $params Parameters for controller
	 * @access public
	 */
	function error500($params) {
		extract($params, EXTR_OVERWRITE);

		if (!isset($url)) {
			$url = $this->controller->here;
		}
		$url = Router::normalize($url);
		$this->controller->header("HTTP/1.0 500 Internal Server Error");
		$this->controller->set(array(
			'code' => '500',
			'name' => __('An Internal Error Has Occurred', true),
			'message' => h($url),
			'base' => $this->controller->base
		));
		$this->_outputMessage('error500');
	}
开发者ID:ralmeida,项目名称:FoundFree.org,代码行数:22,代码来源:app_error.php

示例9: admin_login

 /**
  * Auth Login page
  */
 public function admin_login()
 {
     if (Configure::read('Backend.Auth.enabled') !== true) {
         if (isset($this->Auth)) {
             $this->redirect($this->Auth->loginAction);
         } else {
             $this->redirect('/');
         }
     }
     $this->layout = "Backend.auth";
     $defaultRedirect = Configure::read('Backend.Dashboard.url') ? Configure::read('Backend.Dashboard.url') : array('plugin' => 'backend', 'controller' => 'backend', 'action' => 'dashboard');
     $redirect = false;
     if ($this->request->is('post')) {
         if (!$this->Auth->login()) {
             //Event Backend.Auth.onLoginFail
             $eventData = array('user' => $this->request->data['BackendUser'], 'ip' => $this->request->clientIp());
             // $event = new CakeEvent('Backend.Controller.Auth.onLoginFail', $this, $eventData);
             // $this->getEventManager()->dispatch($event);
             $this->Session->setFlash(__d('backend', 'Login failed'), 'error', array(), 'auth');
         } else {
             //Event Backend.Auth.onLogin
             $event = new CakeEvent('Backend.Controller.Auth.onLogin', $this, $this->Auth->user());
             //$this->getEventManager()->dispatch($event);
             $this->Session->setFlash(__d('backend', 'Login successful'), 'success');
             if ($this->Auth->user('lastlogin')) {
                 $this->Session->setFlash(__d('backend', 'Last login: %s', CakeTime::timeAgoInWords($this->Auth->user('last_login'))), 'default', array(), 'auth');
             }
             //TODO should the event result return an redirect url?
             if ($event->result) {
                 $redirect = $event->result;
             } else {
                 $redirect = $this->Auth->redirect();
             }
             $redirect = Router::normalize($redirect);
             if ($redirect == '/' || !preg_match('/^\\/admin\\//', $redirect) || $redirect == '/admin/backend') {
                 $redirect = $defaultRedirect;
             }
             $this->redirect($redirect);
         }
     } elseif ($this->Auth->user()) {
         $redirect = $this->referer($defaultRedirect, true);
         $this->redirect($redirect);
     }
     $this->set(compact('redirect'));
 }
开发者ID:fm-labs,项目名称:cakephp-backend,代码行数:48,代码来源:AuthController.php

示例10: beforeRender

 public function beforeRender($viewFile)
 {
     if (isset($this->request->params['admin'])) {
         return;
     }
     $url = Router::normalize($this->request->url);
     $Url = ClassRegistry::init('Seolite.SeoLiteUrl');
     $data = $Url->find('first', array('fields' => array('id', 'url'), 'recursive' => -1, 'contain' => 'Meta', 'conditions' => array('url' => $url, 'status' => true), 'cache' => array('name' => 'urlmeta_' . Inflector::slug($url), 'config' => 'seo_lite')));
     if (isset($data['CustomFields'])) {
         $metas = array();
         foreach ($data['CustomFields'] as $key => $value) {
             if (strpos($key, 'meta_') !== false) {
                 $metas[str_replace('meta_', '', $key)] = $value;
             }
         }
         Configure::write('Meta', $metas);
     }
 }
开发者ID:xintesa,项目名称:seolite,代码行数:18,代码来源:SeoLiteHelper.php

示例11: redirect

 function redirect($url = null)
 {
     //		if (!is_null($url)) {
     //			$redir = $url;
     //			$this->Session->write('Auth.redirect', $redir);
     //		} elseif ($this->Session->check('Auth.redirect')) {
     //			$redir = $this->Session->read('Auth.redirect');
     //			$this->Session->delete('Auth.redirect');
     //
     //			if (Router::normalize($redir) == Router::normalize($this->loginAction)) {
     //				$redir = $this->loginRedirect;
     //			}
     //		} else {
     //			$redir = $this->loginRedirect;
     //		}
     $this->successedRedirect = array(Configure::read('Routing.admin') => true, 'controller' => 'dashboard', 'action' => 'index');
     //		var_dump($this->successedRedirect);
     return Router::normalize($this->successedRedirect);
 }
开发者ID:laiello,项目名称:myopensources,代码行数:19,代码来源:auths.php

示例12: check

 /**
  * check method
  *
  * If they're trying to logout - delete the remember me cookie if it exists and disable further processing
  * If there's already a user logged in, there's nothing this component needs to do so disable the component
  * Else check for cookie data, and attempt to log in if found
  *
  * @return void
  * @access public
 */
 function check()
 {
     if (!isset($this->Controller)) {
         return;
     }
     $url = Router::normalize($this->Controller->params['url']);
     if ($url === Router::normalize($this->settings['auth']['logoutAction'])) {
         $this->Controller->Auth->logout();
         $this->_cookieDestroy();
         $this->log('Disabling - logging out');
         $this->enabled = false;
         return;
     }
     if ($this->__authUserId) {
         $this->log('Disabling - User already logged in');
         $this->enabled = false;
         return;
     }
     if ($this->Auth->Session->started() && $this->_cookieAuth()) {
         $this->log('Disabling - Nothing else to do');
         $this->enabled = false;
         return;
     }
     if ($url === Router::normalize($this->settings['auth']['loginAction'])) {
         $this->enabled = true;
         return;
     }
     $this->enabled = false;
 }
开发者ID:razzman,项目名称:mi_users,代码行数:39,代码来源:RememberMeComponent.php

示例13: testUserLogin

 /**
  * Test the user login
  *
  * @return void
  */
 public function testUserLogin()
 {
     $this->Users->request->params['action'] = 'login';
     $this->__setPost(array('User' => $this->usersData['admin']));
     $this->Users->request->url = '/users/users/login';
     $this->Collection = $this->getMock('ComponentCollection');
     $this->Users->Auth = $this->getMock('AuthComponent', array('login', 'user', 'redirect'), array($this->Collection));
     $this->Users->Auth->expects($this->once())->method('login')->will($this->returnValue(true));
     $this->Users->Auth->staticExpects($this->at(0))->method('user')->with('id')->will($this->returnValue(1));
     $this->Users->Auth->staticExpects($this->at(1))->method('user')->with('username')->will($this->returnValue('adminuser'));
     $this->Users->Auth->expects($this->once())->method('redirect')->with(null)->will($this->returnValue(Router::normalize('/')));
     $this->Users->Session = $this->getMock('SessionComponent', array('setFlash'), array($this->Collection));
     $this->Users->Session->expects($this->any())->method('setFlash')->with(__d('users', 'adminuser you have successfully logged in'));
     $this->Users->RememberMe = $this->getMock('RememberMeComponent', array(), array($this->Collection));
     $this->Users->RememberMe->expects($this->any())->method('destroyCookie');
     $this->Users->login();
     $this->assertEqual(Router::normalize($this->Users->redirectUrl), Router::normalize(Router::url($this->Users->Auth->loginRedirect)));
 }
开发者ID:sh1omi,项目名称:xlrstats-web-v3,代码行数:23,代码来源:UsersControllerTest.php

示例14: testLoginRedirect

 /**
  * testLoginRedirect method
  *
  * @access public
  * @return void
  */
 function testLoginRedirect()
 {
     if (isset($_SERVER['HTTP_REFERER'])) {
         $backup = $_SERVER['HTTP_REFERER'];
     } else {
         $backup = null;
     }
     $_SERVER['HTTP_REFERER'] = false;
     $this->Controller->Session->write('Auth', array('AuthUser' => array('id' => '1', 'username' => 'nate')));
     $this->Controller->params = Router::parse('users/login');
     $this->Controller->params['url']['url'] = 'users/login';
     $this->Controller->Auth->initialize($this->Controller);
     $this->Controller->Auth->userModel = 'AuthUser';
     $this->Controller->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'display', 'welcome');
     $this->Controller->Auth->startup($this->Controller);
     $expected = Router::normalize($this->Controller->Auth->loginRedirect);
     $this->assertEqual($expected, $this->Controller->Auth->redirect());
     $this->Controller->Session->del('Auth');
     $this->Controller->params['url']['url'] = 'admin/';
     $this->Controller->Auth->initialize($this->Controller);
     $this->Controller->Auth->userModel = 'AuthUser';
     $this->Controller->Auth->loginRedirect = null;
     $this->Controller->Auth->startup($this->Controller);
     $expected = Router::normalize('admin/');
     $this->assertTrue($this->Controller->Session->check('Message.auth'));
     $this->assertEqual($expected, $this->Controller->Auth->redirect());
     $this->Controller->Session->del('Auth');
     //empty referer no session
     $_SERVER['HTTP_REFERER'] = false;
     $_ENV['HTTP_REFERER'] = false;
     putenv('HTTP_REFERER=');
     $url = '/posts/view/1';
     $this->Controller->Session->write('Auth', array('AuthUser' => array('id' => '1', 'username' => 'nate')));
     $this->Controller->testUrl = null;
     $this->Controller->params = Router::parse($url);
     array_push($this->Controller->methods, 'view', 'edit', 'index');
     $this->Controller->Auth->initialize($this->Controller);
     $this->Controller->Auth->authorize = 'controller';
     $this->Controller->params['testControllerAuth'] = true;
     $this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
     $this->Controller->Auth->userModel = 'AuthUser';
     $this->Controller->Auth->startup($this->Controller);
     $expected = Router::normalize('/');
     $this->assertEqual($expected, $this->Controller->testUrl);
     $this->Controller->Session->del('Auth');
     $_SERVER['HTTP_REFERER'] = Router::url('/admin/', true);
     $this->Controller->Session->write('Auth', array('AuthUser' => array('id' => '1', 'username' => 'nate')));
     $this->Controller->params['url']['url'] = 'auth_test/login';
     $this->Controller->Auth->initialize($this->Controller);
     $this->Controller->Auth->loginAction = 'auth_test/login';
     $this->Controller->Auth->userModel = 'AuthUser';
     $this->Controller->Auth->loginRedirect = false;
     $this->Controller->Auth->startup($this->Controller);
     $expected = Router::normalize('/admin');
     $this->assertEqual($expected, $this->Controller->Auth->redirect());
     //Ticket #4750
     //named params
     $this->Controller->Session->del('Auth');
     $url = '/posts/index/year:2008/month:feb';
     $this->Controller->params = Router::parse($url);
     $this->Controller->params['url']['url'] = Router::normalize($url);
     $this->Controller->Auth->initialize($this->Controller);
     $this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
     $this->Controller->Auth->userModel = 'AuthUser';
     $this->Controller->Auth->startup($this->Controller);
     $expected = Router::normalize('posts/index/year:2008/month:feb');
     $this->assertEqual($expected, $this->Controller->Session->read('Auth.redirect'));
     //passed args
     $this->Controller->Session->del('Auth');
     $url = '/posts/view/1';
     $this->Controller->params = Router::parse($url);
     $this->Controller->params['url']['url'] = Router::normalize($url);
     $this->Controller->Auth->initialize($this->Controller);
     $this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
     $this->Controller->Auth->userModel = 'AuthUser';
     $this->Controller->Auth->startup($this->Controller);
     $expected = Router::normalize('posts/view/1');
     $this->assertEqual($expected, $this->Controller->Session->read('Auth.redirect'));
     // QueryString parameters
     $this->Controller->Session->del('Auth');
     $url = '/posts/index/29?print=true&refer=menu';
     $this->Controller->params = Router::parse($url);
     $this->Controller->params['url']['url'] = Router::normalize($url);
     $this->Controller->Auth->initialize($this->Controller);
     $this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
     $this->Controller->Auth->userModel = 'AuthUser';
     $this->Controller->Auth->startup($this->Controller);
     $expected = Router::normalize('posts/index/29?print=true&refer=menu');
     $this->assertEqual($expected, $this->Controller->Session->read('Auth.redirect'));
     //external authed action
     $_SERVER['HTTP_REFERER'] = 'http://webmail.example.com/view/message';
     $this->Controller->Session->del('Auth');
     $url = '/posts/edit/1';
     $this->Controller->params = Router::parse($url);
//.........这里部分代码省略.........
开发者ID:hardsshah,项目名称:bookmarks,代码行数:101,代码来源:auth.test.php

示例15: testRedirectUrlWithBaseSet

 /**
  * test that the returned URL doesn't contain the base URL.
  *
  * @see https://cakephp.lighthouseapp.com/projects/42648/tickets/3922-authcomponentredirecturl-prepends-appbaseurl
  *
  * @return void This test method doesn't return anything.
  */
 public function testRedirectUrlWithBaseSet()
 {
     $App = Configure::read('App');
     Configure::write('App', array('dir' => APP_DIR, 'webroot' => WEBROOT_DIR, 'base' => false, 'baseUrl' => '/cake/index.php'));
     $url = '/users/login';
     $this->Auth->request = $this->Controller->request = new CakeRequest($url);
     $this->Auth->request->addParams(Router::parse($url));
     $this->Auth->request->url = Router::normalize($url);
     Router::setRequestInfo($this->Auth->request);
     $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
     $this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'home');
     $result = $this->Auth->redirectUrl();
     $this->assertEquals('/users/home', $result);
     $this->assertFalse($this->Auth->Session->check('Auth.redirect'));
     Configure::write('App', $App);
     Router::reload();
 }
开发者ID:gbdeboer,项目名称:letterbox-backend,代码行数:24,代码来源:AuthComponentTest.php


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