Help for htacces or routing |
I have this scenario:
One controller called Brands with relative class Brands. Inside this controller the following functions: index() - This is showing the list of all brands inside my db show($slug) - This is showing the detail of the brand clicked and all list of the products related with that brand. detail($slug) - This is showing the detail of one product belonging to the previous product list When I call index, as normal, I have a url like that: - http://localhost/brands When I click on a brand of this list, I have an url like that: - http://localhost/brands/show/apple When I click on a product of this list, I have an url like that: - http://localhost/brands/detail/macbook-13-retina I would like to have previous urls in this form: - http://localhost/brands - http://localhost/brands/apple - http://localhost/brands/apple/macbook-13-retina Now, I've read a lot of tutorials and I've read how to routing library works, but I can't understand if routes can help me more than a htaccess. Also, the cms I'm building can be installed with a different language than English, so I can have for example: - http://localhost/brands but as well - http://localhost/marcas or - http://localhost/marche How can I use routing or htaccess for to get the above changes? Can someone help me? Thank you very much in advance... Giorgio
Hi,
I think the language part of your question is a seperate issue all by itself. In response to this: Code: - http://localhost/brands Without routes you could easily achieve this in one controller. controller Brands.php PHP Code: public function index($brand='', $product='') { Or with routes you could do PHP Code: $route['brands/:any/:any'] = 'catalog/product_lookup/$1/$2'; Hope that helps, Paul. PS Routes docs are here: https://www.codeigniter.com/user_guide/g...uting.html
Then of course, once that is working, you could add:
PHP Code: $route['marcas/:any/:any'] = 'catalog/product_lookup/$1/$2'; And similar for other languages. But that really depends how you choose to go about implementing a multi-lingual site. There are lots of options and no real 'best' answer, just what suits your site. Paul.
Hi Paul and thank you one more time for your help
I was reading with attention the route config file guide and I have to say that it was a misunderstanding in my topic. So route is: Code: $route['brands'] = 'categories'; This example above says that if routing class found in the url the word 'brands', that link is remapped to a controller categories. So 'categories' is something that already have to exist. This is a remapped. In fact, putting: Code: $route['brands'] = 'categories'; Code: $route['brands'] = 'my_word_is_not_a_controller_or_function'; I don't want a remapped action, I want a rewrite action. In my idea, I'd like that the normal class/method/param were mapped correctly but with other words, beacuse of the slugs are depending by the user that introduces data... I hope I explain good myself... Please tell me if my thought is correct... Giorgio ![]()
After days and days I solved my problem...
I interpreted in a bad way your reply, but after I understood it and I solve it. Thanks a lot! |
Welcome Guest, Not a member yet? Register Sign In |