本文整理汇总了PHP中Router::reverse方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::reverse方法的具体用法?PHP Router::reverse怎么用?PHP Router::reverse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Router
的用法示例。
在下文中一共展示了Router::reverse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/**
* Parses a string url into an array. Parsed urls will result in an automatic
* redirection
*
* @param string $url The url to parse
* @return boolean False on failure
*/
public function parse($url)
{
$params = parent::parse($url);
if (!$params) {
return false;
}
if (!$this->response) {
$this->response = new CakeResponse();
}
$redirect = $this->redirect;
if (count($this->redirect) == 1 && !isset($this->redirect['controller'])) {
$redirect = $this->redirect[0];
}
if (isset($this->options['persist']) && is_array($redirect)) {
$redirect += array('named' => $params['named'], 'pass' => $params['pass'], 'url' => array());
$redirect = Router::reverse($redirect);
}
$status = 301;
if (isset($this->options['status']) && ($this->options['status'] >= 300 && $this->options['status'] < 400)) {
$status = $this->options['status'];
}
$this->response->header(array('Location' => Router::url($redirect, true)));
$this->response->statusCode($status);
$this->response->send();
$this->_stop();
}
示例2: 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.
*
* @param mixed $url String or array-based url.
* @param array $extra if array includes the key "return" it sets the AutoRender to true.
* @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 (in_array('return', $extra, true)) {
$extra = array_merge($extra, array('return' => 0, 'autoRender' => 1));
}
if (is_array($url) && !isset($extra['url'])) {
$extra['url'] = array();
}
$extra = array_merge(array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1), $extra);
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($params['data'])) {
$request->data = $params['data'];
}
}
$dispatcher = new Dispatcher();
return $dispatcher->dispatch($request, new CakeResponse(), $extra);
}
示例3: testRoutableContentTypes
public function testRoutableContentTypes()
{
$Type = ClassRegistry::init('Type');
$type = $Type->create(array('title' => 'Press Release', 'alias' => 'press-release', 'description' => ''));
$Type->save($type);
$type = $Type->findByAlias('press-release');
CroogoRouter::routableContentTypes();
$params = array('url' => array(), 'controller' => 'nodes', 'action' => 'index', 'type' => 'press-release');
$result = Router::reverse($params);
$this->assertEquals('/nodes/index/type:press-release', $result);
$type['Type']['params'] = 'routes=1';
$Type->save($type);
CroogoRouter::routableContentTypes();
$result = Router::reverse($params);
$this->assertEquals('/press-release', $result);
}
示例4: testReverseWithExtension
/**
* Test that extensions work with Router::reverse()
*
* @return void
*/
public function testReverseWithExtension()
{
Router::parseExtensions('json');
$request = new CakeRequest('/posts/view/1.json');
$request->addParams(array('controller' => 'posts', 'action' => 'view', 'pass' => array(1), 'named' => array(), 'ext' => 'json'));
$request->query = array();
$result = Router::reverse($request);
$expected = '/posts/view/1.json';
$this->assertEquals($expected, $result);
}
示例5: 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;
}
if (($index = array_search('return', $extra)) !== false) {
$extra['return'] = 0;
$extra['autoRender'] = 1;
unset($extra[$index]);
}
$arrayUrl = is_array($url);
if ($arrayUrl && !isset($extra['url'])) {
$extra['url'] = array();
}
if ($arrayUrl && !isset($extra['data'])) {
$extra['data'] = array();
}
$extra += array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1);
$data = isset($extra['data']) ? $extra['data'] : null;
unset($extra['data']);
if (is_string($url) && strpos($url, Router::fullBaseUrl()) === 0) {
$url = Router::normalize(str_replace(Router::fullBaseUrl(), '', $url));
}
if (is_string($url)) {
$request = new CakeRequest($url);
} elseif (is_array($url)) {
$params = $url + array('pass' => array(), 'named' => array(), 'base' => false);
$params = $extra + $params;
$request = new CakeRequest(Router::reverse($params));
}
if (isset($data)) {
$request->data = $data;
}
$dispatcher = new Dispatcher();
$result = $dispatcher->dispatch($request, new CakeResponse(), $extra);
Router::popRequest();
return $result;
}
示例6: __extractParams
/**
* Sets the params when $url is passed as an array to Object::requestAction();
* Merges the $url and $additionalParams and creates a string url.
*
* @param array $url Array or request parameters
* @param array $additionalParams Array of additional parameters.
* @return string $url The generated url string.
* @access private
*/
function __extractParams($url, $additionalParams = array())
{
$defaults = array('pass' => array(), 'named' => array(), 'form' => array());
$params = array_merge($defaults, $url, $additionalParams);
$this->params = $params;
$params += array('base' => false, 'url' => array());
return ltrim(Router::reverse($params), '/');
}
示例7: __handlePaginatorArchivable
/**
* Removed archived records from paginated lists by default.
*
* @param void
* @return void
*/
private function __handlePaginatorArchivable($object)
{
$options = $this->_getPaginatorVars($object, 'is_archived');
if (!empty($options['schema']['is_archived'])) {
$this->redirect(Router::reverse($this->request->params + array('filter' => 'archived:0', 'url' => null)));
}
}
示例8: startup
/**
* Main execution method. Handles redirecting of invalid users, and processing
* of login form data.
*
* @param Controller $controller A reference to the instantiating controller object
* @return boolean
*/
public function startup($controller)
{
if ($controller->name == 'CakeError') {
return true;
}
$methods = array_flip(array_map('strtolower', $controller->methods));
$action = strtolower($controller->request->params['action']);
$isMissingAction = $controller->scaffold === false && !isset($methods[$action]);
if ($isMissingAction) {
return true;
}
if (!$this->_setDefaults()) {
return false;
}
$request = $controller->request;
$url = '';
if (isset($request->url)) {
$url = $request->url;
}
$url = Router::normalize($url);
$loginAction = Router::normalize($this->loginAction);
$allowedActions = $this->allowedActions;
$isAllowed = $this->allowedActions == array('*') || in_array($action, array_map('strtolower', $allowedActions));
if ($loginAction != $url && $isAllowed) {
return true;
}
if ($loginAction == $url) {
if (empty($request->data)) {
if (!$this->Session->check('Auth.redirect') && !$this->loginRedirect && env('HTTP_REFERER')) {
$this->Session->write('Auth.redirect', $controller->referer(null, true));
}
}
return true;
} else {
if (!$this->_getUser()) {
if (!$request->is('ajax')) {
$this->flash($this->authError);
$this->Session->write('Auth.redirect', Router::reverse($request));
$controller->redirect($loginAction);
return false;
} elseif (!empty($this->ajaxLogin)) {
$controller->viewPath = 'Elements';
echo $controller->render($this->ajaxLogin, $this->RequestHandler->ajaxLayout);
$this->_stop();
return false;
} else {
$controller->redirect(null, 403);
}
}
}
if (empty($this->authorize) || $this->isAuthorized($this->user())) {
return true;
}
$this->flash($this->authError);
$controller->redirect($controller->referer('/'), null, true);
return false;
}
示例9: _url
/**
* This is used instead of the above on one site who's feature I'm integrating.
* I only see serializedTemplateRequest() being used in updateTemplateSettings() anyway.. so might be able to just use this.
*
* @param array $data
* @return string
*/
public function _url($data)
{
if (empty($data['Webpage']['url']) && !empty($data['Webpage']['id'])) {
$data = array('admin' => false, 'plugin' => 'webpages', 'controller' => 'webpages', 'action' => 'view', $data['Webpage']['id']);
}
if ($data['plugin'] == 'webpages' && $data['controller'] == 'webpages' && $data['action'] == 'view') {
return 'webpages/webpages/view/' . $data[0] . '/';
// webpages get special treatment
$url = @Router::reverse($data);
// seems to be returning the slug URL; possibly because we are now using routes.php
$url = strpos($url, '/') === 0 ? substr($url, 1) . '/' : $url . '/';
} elseif ($data['action'] == 'index') {
$url = $data['plugin'] . '/' . $data['controller'] . '/' . $data['action'] . '*';
} else {
unset($data['pass']);
unset($data['named']);
$url = @Router::reverse($data) . '/*';
}
return $url;
}
示例10: authorize
/**
* Authorize user
*
* Accepts a `client_id` and optional `client_secret` query string and,
* based on a `response_type`, returns a newly minted `code` or `token`.
*
* @author Anthony Putignano <anthony@wizehive.com>
* @since 0.1
* @return void
*/
public function authorize()
{
$user_id = $this->Session->read('Auth.' . $this->authorizeActionSettings['userIdKey']);
if (empty($user_id)) {
$this->Session->write('Auth.redirect', Router::reverse($this->request));
return $this->redirect($this->authorizeActionSettings['loginUrl'], 401);
}
$client_data = $this->OAuth2->validateAuthorizeRequest();
if (empty($client_data)) {
return false;
}
$api_key = $client_data['client_id'];
$post_scope = !empty($this->request->data['scope']) ? $this->request->data['scope'] : null;
$get_scope = !empty($this->request->query['scope']) ? $this->request->query['scope'] : null;
$scope = !empty($post_scope) ? $post_scope : $get_scope;
if (!isset($this->OAuth2Authorization)) {
$this->loadModel('OAuth2.OAuth2Authorization');
}
$existing_authorization = $this->OAuth2Authorization->getExisting($api_key, $user_id, $scope);
$show_permissions_page = false;
if (empty($existing_authorization) && $this->request->is('get')) {
$show_permissions_page = true;
}
$proceed_with_authorization = false;
if (!empty($existing_authorization) || $this->request->is('post')) {
$proceed_with_authorization = true;
}
if ($show_permissions_page) {
$this->set('client', $client_data);
} elseif ($proceed_with_authorization) {
$allow = false;
if (!empty($existing_authorization) || !empty($this->request->data['allow'])) {
$allow = true;
}
$response = $this->OAuth2->handleAuthorizeRequest($allow, $user_id);
if (empty($response)) {
return false;
}
return $this->redirect($response->getHttpHeader('Location'), $response->getStatusCode());
}
}
示例11: beforeFilter
/**
* beforeFilter
*
* @return void
*/
public function beforeFilter()
{
parent::beforeFilter();
$isRequestView = $this->request->is('requestview');
$isUpdate = $this->request->is('update');
$isAdmin = $this->request->is('admin');
$isInstall = $this->request->is('install');
$isMaintenance = $this->request->is('maintenance');
// 設定されたサイトURLとリクエストされたサイトURLが違う場合は設定されたサイトにリダイレクト
if ($isAdmin) {
if ($this->request->is('ssl')) {
$siteUrl = Configure::read('BcEnv.sslUrl');
} else {
$siteUrl = Configure::read('BcEnv.siteUrl');
}
if ($siteUrl && siteUrl() != $siteUrl) {
$this->redirect($siteUrl . preg_replace('/^\\//', '', Router::reverse($this->request, false)));
}
}
// メンテナンス
if (!empty($this->siteConfigs['maintenance']) && Configure::read('debug') < 1 && !$isMaintenance && !$isAdmin && !BcUtil::isAdminUser()) {
if (!empty($this->request->params['return']) && !empty($this->request->params['requested'])) {
return;
} else {
$redirectUrl = '/maintenance';
if ($this->request->params['Site']['alias']) {
$redirectUrl = '/' . $this->request->params['Site']['alias'] . $redirectUrl;
}
$this->redirect($redirectUrl);
}
}
// セキュリティ設定
$this->Security->blackHoleCallback = '_blackHoleCallback';
if (!BC_INSTALLED || $isUpdate) {
$this->Security->validatePost = false;
}
if ($isAdmin) {
$this->Security->validatePost = false;
$corePlugins = Configure::read('BcApp.corePlugins');
if (BC_INSTALLED && (!$this->plugin || in_array($this->plugin, $corePlugins)) && Configure::read('debug') === 0) {
$this->Security->csrfCheck = true;
} else {
$this->Security->csrfCheck = false;
}
// SSLリダイレクト設定
if (Configure::read('BcApp.adminSsl')) {
$adminSslMethods = array_filter(get_class_methods(get_class($this)), array($this, '_adminSslMethods'));
if ($adminSslMethods) {
$this->Security->requireSecure = $adminSslMethods;
}
}
}
//$this->Security->validatePost = false;
// 送信データの文字コードを内部エンコーディングに変換
$this->__convertEncodingHttpInput();
// $this->request->query['url'] の調整
// 環境によって?キーにamp;が付加されてしまうため
if (isset($this->request->query) && is_array($this->request->query)) {
foreach ($this->request->query as $key => $val) {
if (strpos($key, 'amp;') === 0) {
$this->request->query[substr($key, 4)] = $val;
unset($this->request->query[$key]);
}
}
}
// コンソールから利用される場合、$isInstall だけでは判定できないので、BC_INSTALLED も判定に入れる
if (!BC_INSTALLED || $isInstall || $isUpdate) {
return;
}
// Ajax ヘッダー
if ($this->request->is('ajax')) {
// キャッシュ対策
header("Cache-Control: no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
}
// テーマ内プラグインのテンプレートをテーマに梱包できるようにプラグインパスにテーマのパスを追加
// ===============================================================================
// 実際には、プラグインの場合も下記パスがテンプレートの検索対象となっている為不要だが、
// ビューが存在しない場合に、プラグインテンプレートの正規のパスがエラーメッセージに
// 表示されてしまうので明示的に指定している。
// (例)
// [変更後] app/webroot/theme/demo/blog/news/index.php
// [正 規] app/plugins/blog/views/theme/demo/blog/news/index.php
// 但し、CakePHPの仕様としてはテーマ内にプラグインのテンプレートを梱包できる仕様となっていないので
// 将来的には、blog / mail / feed をプラグインではなくコアへのパッケージングを検討する必要あり。
// ※ AppView::_pathsも関連している
// ===============================================================================
$pluginThemePath = WWW_ROOT . 'theme' . DS . $this->theme . DS;
$pluginPaths = Configure::read('pluginPaths');
if ($pluginPaths && !in_array($pluginThemePath, $pluginPaths)) {
Configure::write('pluginPaths', am(array($pluginThemePath), $pluginPaths));
}
// 認証設定
if (isset($this->BcAuthConfigure)) {
//.........这里部分代码省略.........
示例12: 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 mixed $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)) {
$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;
}
示例13: testRouterReverse
/**
* test reversing parameter arrays back into strings.
*
* @return void
*/
public function testRouterReverse()
{
$params = array('controller' => 'posts', 'action' => 'view', 'pass' => array(1), 'named' => array(), 'url' => array(), 'autoRender' => 1, 'bare' => 1, 'return' => 1, 'requested' => 1, '_Token' => array('key' => 'sekret'));
$result = Router::reverse($params);
$this->assertEqual($result, '/posts/view/1');
$params = array('controller' => 'posts', 'action' => 'index', 'pass' => array(1), 'named' => array('page' => 1, 'sort' => 'Article.title', 'direction' => 'desc'), 'url' => array());
$result = Router::reverse($params);
$this->assertEqual($result, '/posts/index/1/page:1/sort:Article.title/direction:desc');
Router::connect('/:lang/:controller/:action/*', array(), array('lang' => '[a-z]{3}'));
$params = array('lang' => 'eng', 'controller' => 'posts', 'action' => 'view', 'pass' => array(1), 'named' => array(), 'url' => array('url' => 'eng/posts/view/1'));
$result = Router::reverse($params);
$this->assertEqual($result, '/eng/posts/view/1');
$params = array('lang' => 'eng', 'controller' => 'posts', 'action' => 'view', 'pass' => array(1), 'named' => array(), 'url' => array('url' => 'eng/posts/view/1', 'foo' => 'bar', 'baz' => 'quu'), 'paging' => array(), 'models' => array());
$result = Router::reverse($params);
$this->assertEqual($result, '/eng/posts/view/1?foo=bar&baz=quu');
$request = new CakeRequest('/eng/posts/view/1');
$request->addParams(array('lang' => 'eng', 'controller' => 'posts', 'action' => 'view', 'pass' => array(1), 'named' => array()));
$request->query = array('url' => 'eng/posts/view/1', 'test' => 'value');
$result = Router::reverse($request);
$expected = '/eng/posts/view/1?test=value';
$this->assertEquals($expected, $result);
$params = array('lang' => 'eng', 'controller' => 'posts', 'action' => 'view', 'pass' => array(1), 'named' => array(), 'url' => array('url' => 'eng/posts/view/1'));
$result = Router::reverse($params, true);
$this->assertPattern('/^http(s)?:\\/\\//', $result);
}
示例14: urlReverse
/**
* turn framework-style url (/home/view/4) to routed url (/product/4)
* @param type $url
* @param type $params
* @return type
*/
function urlReverse($url, $params)
{
return $this->url(Router::reverse($url, $params));
}
示例15: admin_destroy
function admin_destroy($id)
{
if (!empty($id) || $this->Xpagin->isExecuter) {
if (empty($id) && !empty($this->data['Xpagin']['record'])) {
$id = $this->data['Xpagin']['record'];
} else {
if (empty($id)) {
$this->Notifier->error($this->Interpreter->process("[:no_items_selected:]"));
$this->redirect($this->referer());
}
}
if ($this->Location->deleteAll(array('id' => $id))) {
$this->Notifier->success($this->Interpreter->process("[:Location_deleted_successfully:]"));
} else {
$this->Notifier->success($this->Interpreter->process("[:an_error_ocurred_on_the_server:]"));
}
$this->redirect(Router::reverse(Router::parse($this->referer())));
} else {
$this->Notifier->error($this->Interpreter->process("[:specify_a_Location_id_add:]"));
}
if (!$this->Xpagin->isExecuter) {
$referer = Router::parse($this->referer());
if ($referer['action'] == 'view') {
$this->redirect(array('action' => 'trash'));
}
$this->redirect($this->referer());
}
}