PHP : actionForward to return a page after AJAX post

<?php
/**
 * @version             $Id: $
 * @category
 * @package     Koowa_Dispatcher
 * @copyright   Copyright (C) 2007 - 2010 John Bell. All rights reserved.
 * @license     GPL(V3)
 * @link
 */

/**
 * Dispatcher
.*
 * @author      John Bell
 * @category    Koowa
 * @package     Koowa_Components
 * @subpackage  Default
 */
class ComFooDispatcher extends ComDefaultDispatcher
{
        /**
        * Forward after a post request
        *
        * Either do a redirect or a execute a browse or read action in the controller
        * depending on the request method and type
        *
        * @return void
        */
        public function _actionForward(KCommandContext $context)
        {
               if (KRequest::type() == 'HTTP')
               {
                      if($redirect = KFactory::get($this->getController())->getRedirect())
                      {
                             KFactory::get('lib.koowa.application')
                                    ->redirect($redirect['url'], $redirect['message'], $redirect['type']);
                      }
               }

               if(KRequest::type() == 'AJAX')
               {
                if( KRequest::get('post.redirect','url')){
                      if($redirect = KFactory::get($this->getController())->getRedirect())
                      {
                             $uri = KFactory::tmp('lib.koowa.http.uri', array('uri' => $redirect['url']) );
                             $filter = KFilter::factory('string');
                             $query = $filter->sanitize($uri->query);
                             $application = $this->_identifier->application;
                             $view = $query['view'];
                             $package = explode('_', $query['option']);
                             unset($query['option']);unset($query['format']);

                             //reset the model
                             KFactory::get($application.'::'.$package[0].'.'.$package[1].'.model.'.KInflector::pluralize($view))->reset();
                             $context->result = KFactory::tmp($application.'::'.$package[0].'.'.$package[1].'.controller.'.KInflector::singularize($view) )
                                    ->set($query)
                                    ->format('ajax')
                                    ->execute(KInflector::isPlural($view) ? 'browse' : 'read');

                      } else {
                                $context->result = "OK";
                      }
                } else {
                        $context->result = 'OK';
                }
                }
                return $context->result;
        }

}
Processing your request, Please wait....

No Responses to “PHP : actionForward to return a page after AJAX post”

Comments (Your Comments)

Leave a Reply

You must be logged in to post a comment.