Welcome Guest, Not a member yet? Register   Sign In
Is there a way of detecting POST data in URL requests before routing them?
#7

[eluser]Fabdrol[/eluser]
[quote author="sorenchr" date="1296059930"][quote author="Fabdrol" date="1296023360"]I think you could make this work with a hook, firing before the POST and GET data is sanitized.
Maybe you could do something like this:

- is $_POST populated?
- set a (global) variable $ajax_data to true
- set a (global) variable $ajax_method with the method name
- set a (global) variable $ajax_params with the parameters

then, in the routes.php file, you could set a dynamic route, something like this:
Code:
if($ajax_data) {
  $params = implode('/', $ajax_params);
  $route["$ajax_controller/$ajax_method"] = "ajax/$ajax_method/$params";
}

I've not tested it myself, but I suppose you could give it a shot...[/quote]

I guess this isn't going to be an easy one. Thanks for the help though.[/quote]

Well, not that hard as it sounds, but maybe you can combine my answer with Cristian's.
Using:
Code:
$route['folder/(:any)'] = "controller/method/$1";
makes it possible to pass as many variables to method as you want (:any can contain /param but also /param/param/param). Now, if you wrap it in a if block, you might be able to prevent the use of hooks:
Code:
if(isset($_POST)) { // or maybe: if($this->input->post('post_name') !== false), but i'm not sure if input is loaded already
    $route['retrieve/(:any)'] = "ajax/retrieve/$1";
    $route['lost/(:any)'] = "ajax/lost/$1";
    // etc
}
That way the route only works when CI gets POST data.

Fabian


Messages In This Thread
Is there a way of detecting POST data in URL requests before routing them? - by El Forum - 01-26-2011, 06:17 AM



Theme © iAndrew 2016 - Forum software by © MyBB