Welcome Guest, Not a member yet? Register   Sign In
Multiple URL Suffix (SOLVED - UPDATED for CI 1.6.0)
#11

[eluser]m4rw3r[/eluser]
Here is another MY_URI.php, this one does not need a special router.php addition:

Code:
<?php
/**
* Modified URI class to enable multiple URL suffixes,
* and a function to retrieve which one is used.
* Separate the suffixes with commas (,).
*/
class MY_URI extends CI_URI{
    /**
     * Remove the suffix from the URL if needed, if a suffix is found, save it in $this->url_suffix.
     *
     * @access    private
     * @return    void
     */    
    function _remove_url_suffix()
    {
        $this->url_suffix = '';
        if  ($this->config->item('url_suffix') != ""){
            // go through every suffix and see if they match
            $suffixes = explode(',',$this->config->item('url_suffix'));
            foreach($suffixes as $suffix){
                $suffix = trim($suffix);
                if(preg_match("|".preg_quote($suffix)."$|", $this->uri_string)){
                    // We have match, remove the suffix and save which one in $this->url_suffix
                    $this->uri_string = preg_replace("|".preg_quote($suffix)."$|", "", $this->uri_string);
                    $this->url_suffix = $suffix;
                    break;
                }
            }
        }
    }
    /**
     * Returns the URL suffix used for this request.
     * @return string
     */
    function get_extension(){
        return $this->url_suffix;
    }
}
?>
#12

[eluser]Code Arachn!d[/eluser]
Is there any particular reason to explicitly specify the extensions in the config? It seems a bit redundant and tedious to maintain, while easier to parse am I missing a downside to having an extension not specified?
#13

[eluser]ejangi[/eluser]
No, I think the idea of putting an extension in the config is purely aesthetic. Whereas the point of my solution (for instance) is to allow me run different code depending on the extension in the URL.
#14

[eluser]Code Arachn!d[/eluser]
I completely agree with your reasoning - I use a similar method to define which template to show (print, mobile, rss etc) by the extension - I'm just not sure why in post #10 the code requires the extensions to be specified to me that seems like more work - rather than just pulling it by the last segment.

my 2c
#15

[eluser]ejangi[/eluser]
Ahhh gotchya - yes I agree.




Theme © iAndrew 2016 - Forum software by © MyBB