Set up routing from database

Is it possible to retrieve a URLs from a database to set up routers? Please give an example.

Thank you

Please describe more clearly your problem, as url format and database :smiley:

Since Router::url() can take a string or array to define a url inside Cake, you could store urls in a database as strings or json types (json will appear as an array in the retrieved entity).

So I don’t see any special problems with doing what you want.

// if Urls is your table and it has a `url` column 

$destination = $this->Urls->get($id);
return $this->redirect(Router::url($destination->url));

In the database I have columns: slug, prefix, controller, action .

I have a total of 2 languages, so the table contains 2 records eg:

slug, prefix, controller, action
/contact-us, Pages, Contact, display – EN
/kontakt, Pages, Contact, display – CZ

In templates I would then like to call links as follows:

<? = $ this->Url->build(['prefix' => Pages, 'Controller' => 'Contact', 'action' => 'display']); ?>

So that it works for other languages. I think all URLs should be loaded into config/routes.php? But how? I don’t want to list manual routes to config/routes.php