CodeIgniter Forums
Database driven urls - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Database driven urls (/thread-76497.html)



Database driven urls - mickrus - 05-18-2020

In CI3 I use following code in routes.php:
PHP Code:
require_once( BASEPATH .'database/DB'EXT );
$db =& DB();
$url trim($_SERVER['REQUEST_URI'],'/');

$query_res $db->query("SELECT * FROM `routes` where name = ?");
$row $query_res->row();
if(isset(
$row)){
    
$route[$url] = $row->path;

for database driven routes.
How can I store routes in DB in CI4?
I want use routes like http://site.com/route1 for different controllers


RE: Database driven urls - jreklund - 05-18-2020

It's the same, but different names.
https://codeigniter.com/user_guide/database/examples.html#initializing-the-database-class
https://codeigniter.com/user_guide/database/queries.html#query-bindings
https://codeigniter.com/user_guide/database/results.html#result-arrays
https://codeigniter.com/user_guide/incoming/routing.html

PHP Code:
/**
 * --------------------------------------------------------------------
 * Route Definitions
 * --------------------------------------------------------------------
 */

$db  Database::connect();
$res $db->query("SELECT * FROM `routes` WHERE `name` = ?"$name);
foreach(
$res->getResult() as $row)
{
    
// ...