Routes in codeigniter 4 with parameters - deesoft service

Routes in codeigniter 4 with parameters

Deepak Tailor Image
Deepak Tailor - Sep 27 2020
Routes in codeigniter 4 with parameters

Optimize your urls in CodeIgniter 4 with our comprehensive guide on utilizing routes and parameters. Create dynamic and customizable URLs for your applications efficiently. URL of codeigniter follows string class, method, argument pattern. It contains the first segment class name, this is our controller file. And the second segment is the method name. And after this, whatever is passed are all arguments.

In this example, the function is named instead of the class and has passed the argument. But the method is passed in the second segment. To create such a URL, custom routes have to be set.

Setting our custom routing rules :

All the custom routing rules that you have to set are in the application / config / routes.php file.

url example:
// set routes :
How to set placeholders

We can access dynamic URL values from placeholders. For example, if the URL has a name or numeric number, we can set the rules on it.

How to set Redirecting routes

First of all, we create a root, define it as a name like ‘about’. Then redirect this route to another route.

How to create group in routes

// how to call url in browser

// how to call url in browser

In Roots we have been given some global options by Codeigniter. We set the rules by doing them.

$routes->add('from', 'to', $options);
$routes->get('from', 'to', $options);
$routes->post('from', 'to', $options);
$routes->put('from', 'to', $options);
$routes->head('from', 'to', $options);
$routes->options('from', 'to', $options);
$routes->delete('from', 'to', $options);
$routes->patch('from', 'to', $options);
$routes->match(['get', 'put'], 'from', 'to', $options);
$routes->resource('photos', $options);
$routes->map($array, $options);
$routes->group('name', $options, function());
How to use dash in urls

In codeigniter, we can also create SEO friendly URLs. By using desh in the URL, for this we have to true setTranslateURIDashs() function in the routes.php file.

How to use codeigniter 404 override

We use this function for page not found. In this function, the name of the controller and the function has to be passed. If the user searches any page and that page is not found, then we get him to show the message of Page Not Found.

	echo view('welcome_message');
Deepak Tailor Image
Deepak Tailor

My name is Deepak tailor as a fullstack developer. I have been in the IT industry (PHP, Nodejs, flutter) for the last 5 years. For professional and customize web development & app development, you can send inquiry on our email.
You can contact him at