Welcome Guest, Not a member yet? Register   Sign In
User Profile URL
#11

[eluser]Pygon[/eluser]
I'd prefer something like this:

Code:
class MY_Router extends CI_Router {

    function MY_Router()
    {
        parent::CI_Router();
    }

    function _validate_request($segments)
    {
        // If the controller doesn't exist...
        if (!file_exists(APPPATH.'controllers/'.$segments[0].EXT))
        {
            //Automagically route the request to the user/display controller
            return array_merge(array("user","display"),$segments);
            
        } else {
            parent::_validate_request($segments);
        }
    }

}
#12

[eluser]Michael Wales[/eluser]
Yeah - my explanation above isn't the best implementation, just the easiest to understand for newer users.

Personally, I extended the Router class to allow SQL queries in the route. I always place this route as the first, so it will perform the SQL query defined the route and if it returns a row, it will follow that route.

An example:
Code:
// domain.com/walesmd
// SQL: SELECT id FROM users WHERE username = walesmd
// End Route: user/profile/36
$route["sql[SELECT id FROM users WHERE username = $1]"] = "user/profile/$1";
#13

[eluser]~Chris~[/eluser]
Hmmm. I see. Yes, what you all say makes sense. I would have never thought about extending the router class, especially adding sql queries into the router. genius. Ill have to read more on extending the router class so I can do the same. Thanks.
#14

[eluser]Pygon[/eluser]
[quote author="Michael Wales" date="1204599848"]Yeah - my explanation above isn't the best implementation, just the easiest to understand for newer users.

Personally, I extended the Router class to allow SQL queries in the route. I always place this route as the first, so it will perform the SQL query defined the route and if it returns a row, it will follow that route.

An example:
Code:
// domain.com/walesmd
// SQL: SELECT id FROM users WHERE username = walesmd
// End Route: user/profile/36
$route["sql[SELECT id FROM users WHERE username = $1]"] = "user/profile/$1";
[/quote]

Rather clean implementation, though i'd hate querying the db on every hit (even when it's not needed).
#15

[eluser]Code Arachn!d[/eluser]
My biggest concern would be issues of sql injection with placing sql in the routes... theoretically parsing from a db would be a lot faster than running IO on the local drive (or in the case of a farm - having to reach out to another server for IO would even worse for scalability).
#16

[eluser]Pygon[/eluser]
Not sure about that, and don't find it likely that you'll be running controllers on different servers and reaching across them anyway. I don't know directly offhand -- but I would assume a cached file_exists is going to be much faster than a row lookup.
#17

[eluser]~Chris~[/eluser]
my understanding of codeigniter has deepened.
#18

[eluser]Pygon[/eluser]
Yes -- It's always good to run into things you don't know how to do.

Working out problems has caused me many times to read and better understand the underlying framework. The more I use CI, the more I realize just how flexible it is, unlike many other frameworks. I do feel there are some areas in which this flexibility could be improved, such as the way the router works, but overall I find everything to be incredibly flexible.
#19

[eluser]Unknown[/eluser]
This:

Quote:$route["sql[SELECT id FROM users WHERE username = $1]"] = "user/profile/$1";

is beautiful, thanks a lot Michael, I did generate routes based on sql queries, but in an ugly, non-CI way.
This is really amazing how much good stuff one can squeeze out of CI.

I'm happy, cheers :lol:




Theme © iAndrew 2016 - Forum software by © MyBB