-1

I want my urls to look like:

www.domain.com/catalog/category_name/category_id/product_name/product_id.

How should my controllers look like to accomplish this?

It's ok for the Controller to have Catalog and Function category_name in it.

But what will be my product controller and function. How can I make a structure like this. Do I need to have a specific file structure?

I use CodeIgniter framework. Thanks for your help.

kmindi
  • 4,524
  • 4
  • 31
  • 47
Sinem Bozacı
  • 45
  • 1
  • 9

3 Answers3

2

your controller method should be like this

<?
//..
    public function category_name($category_id,$product_name,$product_id){
        // some cool code
    }
//..
?>
Abimael Martell
  • 342
  • 1
  • 3
  • 8
  • It's okay like this but i want Catalog Controller's index function shows catalogs, edit function edits catalog.. and url like catalog/5 or catalog/5/products shows the products in category 5 also catalog/5/products/create adds new product to this category so i want to have new controller named products, how my file structure or controller structure should be. Because may be my products have attributes than and i want to write a new controller called attributes in a systematic file structure. in your example i need to add more and more functions to only one controller. – Sinem Bozacı Sep 11 '12 at 23:22
  • take a look to the codeigniter Routing, you can use this method and customize the url – Abimael Martell Sep 11 '12 at 23:26
2

In general the controller must not be changed (if it accepts the product id as parameter). All other information can then be put in the url from the database (querying via the product id and getting related information) through URI Routing changes.

kmindi
  • 4,524
  • 4
  • 31
  • 47
0

As you question is very vague - so is my answer - but this function achieves what you asked

Class Catalog extends CI_Controller
{
     public function category_name ($category_id, $product_name, $product_id)
     {
          // your function
     }
}
Laurence
  • 58,936
  • 21
  • 171
  • 212
  • @Johnny It's okay like this but i want Catalog Controller's index function shows catalogs, edit function edits catalog.. and url like catalog/5 or catalog/5/products shows the products in category 5 also catalog/5/products/create adds new product to this category so i want to have new controller named products, how my file structure or controller structure should be. Because may be my products have attributes than and i want to write a new controller called attributes in a systematic file structure. in your example i need to add more and more functions to only one controller. – Sinem Bozacı Sep 11 '12 at 23:22
  • ...your question is very vague - you need to post more info in your question is get a proper answer – Laurence Sep 11 '12 at 23:24