CodeIgniter Forums

Full Version: Database driven urls
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
It's the same, but different names.
https://codeigniter.com/user_guide/datab...base-class
https://codeigniter.com/user_guide/datab...y-bindings
https://codeigniter.com/user_guide/datab...ult-arrays
https://codeigniter.com/user_guide/incom...uting.html

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

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