#6289: Problem with fake redirect of Ajax request under admin section
---------------------------+------------------------------------------------
    Reporter:  vkosinets   |          Type:  Bug       
      Status:  new         |      Priority:  Medium    
   Milestone:  1.2.x.x     |     Component:  Components
     Version:  1.2 Final   |      Severity:  Normal    
    Keywords:              |   Php_version:  PHP 5     
Cake_version:  1.2.2.8120  |  
---------------------------+------------------------------------------------
 Cake version: 1.2.2.8120 Stable

 I'm trying to create Ajax request to admin action "admin_delete".
 I use the following JS code to perform the request:

 {{{
 function initPage() {
         new Ajax.Request('/admin/operators/delete/58', {
                 method:'get',
                 onSuccess: function(transport){
                         var response = transport.responseText;
                         if (response) {
                                 $('content').update(response);
                         }
                 },
                 onFailure: function(){ alert('Something went wrong...') }
         });
 }

 Event.observe(window, 'load', initPage);
 }}}

 Inside the action I'm trying to use $this->redirect method of the
 Controller class.
 The code is below:


 {{{
 function admin_delete($id = null) {
         $this->autoRender = false;
         if (!empty($id)) {
                 $this->Operator->delete($id);
         }
         $this->redirect(array('action' => 'default'), null, true);
 }
 }}}

 Also I applied the following routes to my app:


 {{{
 Router::connect('/', array('controller' => 'pages', 'action' => 'display',
 'home'));
 Router::connect('/admin', array('controller' => 'operator', 'action' =>
 'default', 'admin' => 1));
 Router::connect('/admin/:controller', array('action' => 'default', 'admin'
 => 1));
 Router::connect('/pages/*', array('controller' => 'pages', 'action' =>
 'display'));
 }}}


 I receive error message from Cake (list of warnings in dispatch.php).

 I expected that the Ajax request will be "redirected" using specific
 Cake's logic for redirecting Ajax request.

 I investigated the problem and found that the redirect for Ajax do not add
 admin_ prefix to the action.

 For myself I resolved this problem in the following way.
 Path: /cake/libs/controller/components/request_handler.php
 Method name: beforeRedirect

 I added the following line:

 {{{
 $url = Router::url($url);
 }}}

 before the line:

 {{{
 echo $this->requestAction($url, array('return'));
 }}}

-- 
Ticket URL: <https://trac.cakephp.org/ticket/6289>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design 
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. 
Our primary goal is to provide a structured framework that enables PHP users at 
all levels to rapidly develop robust web applications, without any loss to 
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"tickets cakephp" group.
To post to this group, send email to tickets-cakephp@googlegroups.com
To unsubscribe from this group, send email to 
tickets-cakephp+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---

  • [CakePHP : The Rapid Dev... CakePHP : The Rapid Development Framework for PHP

Reply via email to