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


PHP Controller::referer方法代码示例

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


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

示例1: goToPage

 /**
  * Calculates the page to redirect to.
  *
  * @param int $topic_id
  * @param int $post_id
  * @param bool $return
  * @return mixed
  */
 public function goToPage($topic_id = null, $post_id = null, $return = false)
 {
     $topic = ClassRegistry::init('Forum.Topic')->getById($topic_id);
     $slug = !empty($topic['Topic']['slug']) ? $topic['Topic']['slug'] : null;
     // Certain page
     if ($topic_id && $post_id) {
         $posts = ClassRegistry::init('Forum.Post')->getIdsForTopic($topic_id);
         $perPage = Configure::read('Forum.settings.postsPerPage');
         $totalPosts = count($posts);
         if ($totalPosts > $perPage) {
             $totalPages = ceil($totalPosts / $perPage);
         } else {
             $totalPages = 1;
         }
         if ($totalPages <= 1) {
             $url = array('plugin' => 'forum', 'controller' => 'topics', 'action' => 'view', $slug, '#' => 'post-' . $post_id);
         } else {
             $posts = array_values($posts);
             $flips = array_flip($posts);
             $position = $flips[$post_id] + 1;
             $goTo = ceil($position / $perPage);
             $url = array('plugin' => 'forum', 'controller' => 'topics', 'action' => 'view', $slug, 'page' => $goTo, '#' => 'post-' . $post_id);
         }
         // First post
     } else {
         if ($topic_id && !$post_id) {
             $url = array('plugin' => 'forum', 'controller' => 'topics', 'action' => 'view', $slug);
             // None
         } else {
             $url = $this->Controller->referer();
             if (!$url || strpos($url, 'delete') !== false) {
                 $url = array('plugin' => 'forum', 'controller' => 'forum', 'action' => 'index');
             }
         }
     }
     if ($return) {
         return $url;
     }
     return $this->Controller->redirect($url);
 }
开发者ID:alescx,项目名称:forum,代码行数:48,代码来源:ForumToolbarComponent.php

示例2: _unauthorized

 /**
  * Handle unauthorized access attempt
  *
  * @param \Cake\Controller\Controller $controller A reference to the controller object
  * @return \Cake\Network\Response
  * @throws \Cake\Network\Exception\ForbiddenException
  */
 protected function _unauthorized(Controller $controller)
 {
     if ($this->_config['unauthorizedRedirect'] === false) {
         throw new ForbiddenException($this->_config['authError']);
     }
     $this->flash($this->_config['authError']);
     if ($this->_config['unauthorizedRedirect'] === true) {
         $default = '/';
         if (!empty($this->_config['loginRedirect'])) {
             $default = $this->_config['loginRedirect'];
         }
         $url = $controller->referer($default, true);
     } else {
         $url = $this->_config['unauthorizedRedirect'];
     }
     return $controller->redirect($url);
 }
开发者ID:ansidev,项目名称:cakephp_blog,代码行数:24,代码来源:AuthComponent.php

示例3: _afterSave

 /**
  * Logic triggered after comment was successfully saved.
  *
  * @param \Cake\Datasource\EntityInterface $comment Comment that was just saved
  * @return void
  */
 protected function _afterSave(EntityInterface $comment)
 {
     $successMessage = $this->config('successMessage');
     if (is_callable($successMessage)) {
         $successMessage = $successMessage($comment, $this->_controller);
     }
     $this->_controller->Flash->success($successMessage, ['key' => 'commentsForm']);
     if ($this->config('redirectOnSuccess')) {
         $redirectTo = $this->config('redirectOnSuccess') === true ? $this->_controller->referer() : $this->config('redirectOnSuccess');
         $this->_controller->redirect($redirectTo);
     }
 }
开发者ID:quickapps-plugins,项目名称:comment,代码行数:18,代码来源:CommentComponent.php

示例4: testRefererSlash

 /**
  * Test that the referer is not absolute if it is '/'.
  *
  * This avoids the base path being applied twice on string urls.
  *
  * @return void
  */
 public function testRefererSlash()
 {
     $request = $this->getMockBuilder('Cake\\Network\\Request')->setMethods(['referer'])->getMock();
     $request->base = '/base';
     Router::pushRequest($request);
     $request->expects($this->any())->method('referer')->will($this->returnValue('/'));
     $controller = new Controller($request);
     $result = $controller->referer('/', true);
     $this->assertEquals('/', $result);
     $controller = new Controller($request);
     $result = $controller->referer('/some/path', true);
     $this->assertEquals('/base/some/path', $result);
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:20,代码来源:ControllerTest.php

示例5: testReferer

 /**
  * testReferer method
  *
  * @return void
  */
 public function testReferer()
 {
     $request = $this->getMock('Cake\\Network\\Request', ['referer']);
     $request->expects($this->any())->method('referer')->with(true)->will($this->returnValue('/posts/index'));
     $Controller = new Controller($request);
     $result = $Controller->referer(null, true);
     $this->assertEquals('/posts/index', $result);
     $request = $this->getMock('Cake\\Network\\Request', ['referer']);
     $request->expects($this->any())->method('referer')->with(true)->will($this->returnValue('/posts/index'));
     $Controller = new Controller($request);
     $result = $Controller->referer(array('controller' => 'posts', 'action' => 'index'), true);
     $this->assertEquals('/posts/index', $result);
     $request = $this->getMock('Cake\\Network\\Request', ['referer']);
     $request->expects($this->any())->method('referer')->with(false)->will($this->returnValue('http://localhost/posts/index'));
     $Controller = new Controller($request);
     $result = $Controller->referer();
     $this->assertEquals('http://localhost/posts/index', $result);
     $Controller = new Controller(null);
     $result = $Controller->referer();
     $this->assertEquals('/', $result);
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:26,代码来源:ControllerTest.php

示例6: log404

 /**
  * SetupComponent::log404()
  *
  * @param bool $notifyAdminOnInternalErrors
  * @return void
  */
 public function log404($notifyAdminOnInternalErrors = false)
 {
     if ($this->Controller->name === 'CakeError') {
         $referer = $this->Controller->referer();
         $this->Controller->log('REF: ' . $referer . ' - URL: ' . $this->Controller->request->url, '404');
     }
 }
开发者ID:dereuromark,项目名称:cakephp-setup,代码行数:13,代码来源:SetupComponent.php


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