Thursday, August 30, 2012

Re: Cakephp 1.3 - Detect if Ajax if session expired

hi.


<?php class TestsController extends AppController {
public function beforeFilter(){
$this->Auth->allow('add');
parent::beforeFilter();
}
public function add(){
if($this->Auth->loggedIn()){  // or if($this->Auth->User())
$return['data'] = 'data';
}
// if the session expired, $return is not defined
if(!isset($return)){
$return['login'] = true; 
}
$this->set('return',$return);
$this->render('ajax_view','ajax');
}
}
?>

/View/Tests/ajax_view.ctp 
<?php 
if(isset($return)){
echo json_encode($return);
?>


Greetings

2012/8/30 Florin Trifu <florin.catalin.trifu@gmail.com>
Hi everyone!

I have the following problem: in my application I have a button that makes an ajax request. If the session expired, the lightbox will load the default login page. I want to detect if the original request came from Ajax but I don't know exactly how to do it, because in app_controller::beforeFilter the request is not Ajax anymore (at least according to $this->RequestHandler->isAjax() ). I have tried to use $this->Auth->ajaxLogin to set a new view for the login if the request comes from an expired session.

Thank you!

Best regards!

--
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
 
 

--
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
 
 

No comments: