本文整理汇总了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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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');
}
}