CodeIgniter Forums
problem with Query database in routes.php file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: problem with Query database in routes.php file (/thread-2038.html)



problem with Query database in routes.php file - El Forum - 07-12-2007

[eluser]widiastono[/eluser]
dear all,

I have problem to query database table in routes.php file, this the details story:

I have table in database which contains some filed

mic_modules
id
name
active

i want to query which modules name is actice and use it to route to my url, sample, if i get query news is active from my mic_modules tables so i can redirect to http://127.0.0.1/ci/index.php/news, but if i can't it when i access http://127.0.0.1/ci/index.php/news i will route to http://127.0.0.1/ci/index.php/default.

Simple explaination is i want to get which modules is active but i query it from database table.

any advice for this problem? please help...

widiastono


problem with Query database in routes.php file - El Forum - 07-12-2007

[eluser]esra[/eluser]
What about adding a uri column to your modules table? Then handle the condition in your controller using an if/else statement that considers the query results. You can use the redirect() function in url helper to handle the routing.


problem with Query database in routes.php file - El Forum - 07-12-2007

[eluser]widiastono[/eluser]
that's bring me to what not i want to...

if i write url --> http:\\127.0.0.1\ci\index.php\xxx

but xxx can't find at controller directory so 404 error page will show, in this case i want this will be redirect to default controller.

if i use route like this

$route['(.*)'] = 'default/$1';

it will wrap all uri and redirect to http:\\127.0.0.1\ci\index.php\default


problem with Query database in routes.php file - El Forum - 07-12-2007

[eluser]widiastono[/eluser]
FIY, i have been try use hooks too but i can't load database at pre_system hooks, any suggestion ???