2014-05-17 91 views
0
  1. HI我已经从那里客户可以点击关键字 搜索的是低于搜索栏或输入搜索窗口关键字,在 情况下,第一,当用户点击关键字search_results用URL中的关键字 打开,但是当用户输入关键字时,它只是根据它给出结果 。
  2. 所以所以 这个我使用,然后在不登录的用户一些search_result我们要求对点击登录按钮 登录&我们重定向从那里 用户在这段时间,我们必须在同一页上重定向登录登录弹出后预定义关键字的两个概念之一链接哪个 来的URL只是在重定向到该URL后重定向会话&中的最后一个URL值之后登录 。

3.我需要关键字帮助输入用户&然后登录,所以需要用相同的关键字页面重定向到用户。重定向到CakePHP中登录后请求的最后一页

function search_result($adKeyword = null){ 

    if(!empty($adKeyword) && $adKeyword != ''){ 

     $this->data['City']['keyword'] = $adKeyword; 
    } 
    //////////////////Maintain fetch data//////////////////// 
    if(!empty($this->data)){  
     //pr($this->data);exit; 
     if($this->data['City']['keyword'] == 'Name or Area of expertise'){ 
      $this->data['City']['keyword'] = ''; 
      $this->set("title_for_layout","Search Result"); 
     } 

     if (empty($this->data['City']['city_name'])) { 

      $this->data['City']['city_name'] = $this->Session->read("Location"); 
     } 

     if($this->data['City']['keyword'] != '') 
      $this->set("title_for_layout",$this->data['City']['keyword']." | Search Result"); 
         //$request_params = Router::getParams(); 
          //$this->Session->write('auth_redirect','/'.$request_params['url']['url']); 
        $this->Session->write('login_referrer',$this->params['url']['url']); 
        $this->Session->write('login_referrers',$this->data['City']['keyword']); 

上述两个会话变量我使用重定向认证后登录

if($this->Auth->user('role_id')== Configure::read('App.Role.Mentee')) { 
         if ($this->Session->check('login_referrer')) { 
            $loginReferrer = $this->Session->read('login_referrer'); 
            $this->Session->delete('login_referrer'); 
            //prd($loginReferrer); 
            $this->redirect(SITE_URL."$loginReferrer"); 
            } 
            else if($this->Session->check('login_referrers')) 
            { 

            $loginReferrers = $this->Session->read('login_referrers'); 
            $this->Session->delete('login_referrers'); 
            //prd($loginReferrers); 
            $this->redirect(array('controller'=>'fronts','action'=>'search_result/','$adKeyword' => $loginReferrers)); 
            } 
            else { 
            $this->redirect(array('controller'=>'fronts','action'=>'index')); 
            } 

什么发生了不会else if语句可请帮我

回答

0

如果他们浏览一些页面,并要求登录,那么他们应该重定向到登录后的页面

这就是what the Auth component does by default。因此,以获得所需的行为,登录功能应该类似于:

public function login() { 
    if ($this->request->is('post')) { 
     if ($this->Auth->login()) { 
      return $this->redirect($this->Auth->redirect()); 
     } 
     $this->Session->setFlash(__('Invalid username or password, try again')); 
    } 
} 

注意使用$this->Auth->redirect()返回的URL重定向用户,这个例子是直接从the documentation拍摄。

要更改默认身份验证重定向网址,请修改身份验证组件的loginRedirect属性(例如,从您的beforeFilter中)。

+0

这是不工作,我再次告诉你我的情况就像在search_result页面上,我们已经设置了一个按钮,在屏幕上的一些结果后,一个按钮在底部检查更多,所以如果用户已经登录状态,那么它会给出结果,否则我们的登录弹出如果用户没有登录或注册。所以我需要在这种情况下重定向到他登录的相同页面 – Ankit

+0

您的上述评论是否与问题不同?如果是这样,我没有看到它 - 请为问题添加额外的信息。如果它“不起作用”1)不要重新实现Auth组件如何设置loginRedirect,如文档2)所示,调试并找出原因 - 登录时会话中有什么?如果您没有链接到验证操作,而是直接从公共页面访问登录操作 - 这就是Auth组件不设置loginRedirect的原因。 – AD7six

0

对于手动登录我已经解决了我的问题,我加入这个代码search_result的动作我front_controller

$request_params = Router::getParams(); 
$this->Session->write('auth_redirect','/'.$request_params['url']['url']); 

而且在我的用户_controller我刚使用这个会话变量:

if($this->Auth->user('role_id')== Configure::read('App.Role.Mentee')) { 
$this->redirect($this->Session->read('auth_redirect')); 
else 
            $this->redirect(array('controller'=>'fronts','action'=>'index')); 

但它并没有完全解决我的问题,我想删除一次重定向后的会话值。但为此它没有破坏路由器会话变量值

相关问题