CodeIgniter Forums
CodeIgniter url routing - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: CodeIgniter url routing (/thread-31611.html)



CodeIgniter url routing - El Forum - 06-25-2010

[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?


CodeIgniter url routing - El Forum - 06-25-2010

[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-guide/general/controllers.html

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

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

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



CodeIgniter url routing - El Forum - 06-26-2010

[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


CodeIgniter url routing - El Forum - 06-26-2010

[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.