CodeIgniter Forums

Full Version: CodeIgniter url routing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Yoosuf Muhammad[/eluser]
Hello CI geeks,

need a small help in url routing, how to do following code snipt work dynamically?

Code:
$route['about']  ="pages/index/1";
$route['about/history']  ="pages/index/3";


how to make it in simgle line?

El Forum

[eluser]pbreit[/eluser]
I don't think you need to use "routes" for that. Instead, create a Controller named "pages" and then Functions for each page. Have a look at the doc page for Controllers: http://ellislab.com/codeigniter/user-gui...llers.html

For example:
Code:
<?php
class Pages extends Controller {

    function index()
    {
        echo 'About Us';
    }

    function history()
    {
        echo 'Our history';
    }
}
?>

El Forum

[eluser]Yoosuf Muhammad[/eluser]
well, if i am using the individual functions yeah the method you mentions is pretty cool, but my case is grabbing via Database as

Code:
function index($id){
/**
* Code to display the DB dumps
**/

}

to do so, i should use a dynamic routing, any quick instant solutions please...
Regards,
Yoosuf

El Forum

[eluser]redcore[/eluser]
Okay, while I'm still a little confused (I was with pbreit) ... are you storing all page content (ie "about", "about/history") in your database? If so, I'm assuming you're setting up that page content IN the database and want CodeIgniter to route based on those values, right?

IF so (big if, I'm clearly not sure what you're ultimately doing) then you'll have to build a script that gets the routes/ids from the database and puts the routes array (for "config/routes.php") together dynamically...

Code:
foreach($query->result() as $row) {
    $routes[] = '$route['.$row->route.'] = "pages/index/'.$row->id.'"';
    }

That's my best shot at figuring out what you're trying to do ATM.