create custom url in codeiginter create custom url in codeiginter codeigniter codeigniter

create custom url in codeiginter


The string you`re humanizing, will be in a field, right?

www.mydomain.com/home/single/New-Dell-Laptop

So, if you select in database for "New Dell Laptop"

It will return 1 record, right? If so, you can configure something like this on Routes in config.

$route['single/{product}'] = 'productController/{product}';

Then when you load productController/New-Dell-Laptop

You can use $this->uri->segment(3) to get the value, and search in Database, retrieve page, and show to user.

You should use something like this:

www.mydomain.com/home/single/34/New-Dell-Laptop

Where 34 will be the id to the page and will be easy to you locate on database, but you should not get troubles to find if you search for "New Dell Laptop"


You can use routes.

In your config/routes.php

require_once( BASEPATH .'database/DB'. EXT );$db =& DB();$query = $db->get('vendor_products');$result = $query->result();foreach( $result as $row ){    $route["home/single/" . $row->product_name] = "home/single/" . $row->prod_id;} 

And then in your view, change

<a href="<?=base_url();?>home/single/<?=$one['prod_id'];?>">`

by

<a href="<?=base_url();?>home/single/<?=$one['product_name'];?>">`