Welcome Guest, Not a member yet? Register   Sign In
URL's like : www.something.com/controller/class/function/id/product_title
#1

[eluser]Unknown[/eluser]
I want to have url's in my codeigniter application like : www.something.com/controller/class/function/id/product_title , where id is any product number which is unique, and the product title is an any combination of albhabets which will be taken from the mysql database by fetching a single unique row. so how can i do that, i searched on net and found nothing useful about it, please help.
#2

[eluser]adityamenon[/eluser]
It looks like ID is the identifier of the product, and codeigniter has nothing to do with the "Product title". In the place you are generating links to your products, fetch a tiny bit of the product title, use str_replace() to get rid of the spaces and put in dashes. Concatenate that with the generated URL. In the controller function that takes care of generating the product page, ignore the "product title" - it will be passed as the second argument. Just make room for it in the function declaration and ignore it afterwards.
#3

[eluser]mr lister[/eluser]
First off, your URL is incorrect - refer to CodeIgniter URLs on how it is constructed.

Should be along the lines of:
Code:
example.com/class/function/id/product_title
drop your 'controller' segment before the 'class' segment, but this point is probably moot.

As adityamenon is alluding too, this is how it could look:
Code:
<?php
class Products extends CI_Controller {

public function shoes($sandals, $id)
{
  echo $sandals;
  echo $id;
}
}
?>
the above example is from CodeIgniter User Guide - Controllers.

You can then query your database using the variables.

If, as you mention the 'product id' is unique, it will return a single row if your query is correct.

I suggest you have a read of the CodeIgniter User Guide - I found it very helpful and it explains very well what you wish to achieve.
#4

[eluser]vitoco[/eluser]
what you say/want
Code:
http://www.something.com/controller/class/function/id/product_title
the way it is/must be
Code:
http://www.something.com/[folder]/controller/function/[param_1]/[param_1]
http://www.something.com/[folder]/controller/function/id/product_title

so in the controller, in order to get the params from the uri
Code:
function show_product()
{
    // PARAMS SEGMENTS START AT 3 IF THE CONTROLLER ISN'T IN A SUBFOLDER
    $id = (int) $this->uri->segment( 3 ); //
    $producto_title = $this->uri->segment( 4 ); //
    ....
}

Also, as CI allows only a limited list of characters in the url, the "product_title" must be passed througth the function
Code:
url_title()
in the url_helper http://ellislab.com/codeigniter/user-gui...elper.html

Hope it helps. Saludos




Theme © iAndrew 2016 - Forum software by © MyBB