Welcome Guest, Not a member yet? Register   Sign In
[Solved] Extracting Routes with Hard-Coded URL
#1

[eluser]Madalina.C[/eluser]
Hello

I'm using AJAX POST to pass CI a hard-coded URL from my site.

Lets say this URL that I pass in, and wish to dissect, is

Code:
http://mysite.com/dog/moo/123/

I am looking for a way to use the existing routes.php to extract 'dog', 'moo', '123' according to the regex I provided.

Here is what I've tried

1) Searching these forums for the solution

2) Modifying the $_SERVER param BEFORE my AJAX-receiving class is instantiated. (but
Code:
print_r($this->uri);
still returns the info about the AJAX script rather than the hard-coded URL I receive via AJAX

3) Messing around with the router class but it seems to only use $_SERVER values.

Any help is appreciated

Thank you!
- Madalina
#2

[eluser]WanWizard[/eluser]
How do you 'pass' a URL? And what do you mean by 'info about the AJAX script'?
#3

[eluser]Madalina.C[/eluser]
I'm passing a $URL via AJAX-POST to my PHP script


The $URL is listed above in the example


When I do $this->uri it has the routes already broken up, but it uses the properties of the AJAX script on the remote server, rather than the $URL I pass in.

I'd like, given a $URL, break up the $URL in the segments according to what is defined in routes.php
#4

[eluser]Madalina.C[/eluser]
Just to clear up confusion, here is the most basic way to explain:

My Site

Take $URL and send to

PHP backend

with AJAX.

(PHP backend is my CI installation.)

backend
Take the $URL and apply route parsing to it. Save the results in an array
#5

[eluser]Madalina.C[/eluser]
Well FYI I solved it:

Code:
public function parseURL($url){
        //make things easier, trick the server with our passed-in URL
        $_SERVER['PATH_INFO'] = $url;
        $_SERVER['QUERY_STRING'] = $url;
        
        //set the URL as we want it
        $this->uri->uri_string = $url;
        
        // Compile the segments into an array
        $this->uri->_explode_segments();

        //the first few items in array are redundant info. Rather than writing code to parse it out
        //just manually cut it out
        $this->uri->segments = array_splice($this->uri->segments, 4, count($this->uri->segments));
        
        //let the segments and rsegments be parsed
        $this->router->_parse_routes();    
    }




Theme © iAndrew 2016 - Forum software by © MyBB