hi.

<?php class AppController extends Controller {

public function beforeFilter(){
 if ($this->Auth->User()){
 }else{
// if the session expired
$return['login'] = true;
echo json_encode($return); // responseText: "{"login":true}"
}
 }
} ?>


And the previous code is more simpler now:

<?php class TestsController extends AppController {
 public function add(){
if($this->Auth->loggedIn()){  // or if($this->Auth->User())
 $return['data'] = 'data';
 $this->set('return',$return);
}
$this->render('ajax_view','ajax');
}
}
?>


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

Best regards!

2012/8/30 Florin Trifu <[email protected]>

> Thank you!
>
> The thing is that the application was written in Cakephp 1.3 and we are
> not planning to upgrade it any time soon. Thank you for your warning.
>
> The solution provided is very cool, but I'm looking for something that can
> be implemented in app_controller. This way, it will be global and I will
> not need to change all the controllers the way they act.
> Of course that I will do it your way if this is not possible, but I would
> be very glad to have another solution since the application is huge.
>
> Thank you!
>
> Best regards!
>
>
> On Fri, Aug 31, 2012 at 4:02 AM, romel javier gomez herrera <
> [email protected]> wrote:
>
>> hi.
>>
>> RequestHandler will be discontinued
>> http://book.cakephp.org/2.0/en/appendices/2-0-migration-guide.html#requesthandlercomponent
>>
>> <?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 <[email protected]>
>>
>>> 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 [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> 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 [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> 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 [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.


Reply via email to