id replace the url

#1
[eluser]cmarra[/eluser]
Hello, how can I sotituire id in a url like
example.com/index.php/products/shoes/show/123

with a name of a file?

for example if 123 is the id of a file, I can make the URL
example.com/index.php/products/shoes/show/guide_php

#2
[eluser]pickupman[/eluser]
Similar to how must CMS systems work. Pass the parameter to your function, lookup "slug" (filename) in database for the file / file id, and handle accordingly. You could use a regular expression to make it work for either or.
Code:
function shoes(){
   $action = $this->uri->segment(3,'view');

   switch($action){
     case 'show':
      if(preg_match('/\d++/')){
         $product_id = $this->uri->segment(4);
      }else{
         $product_id = $this->product_model->getShoes($this->uri->segment(4))->row(0)->shoes_id;
      }
     break;
     //other actions here
   }
}

#3
[eluser]cmarra[/eluser]
maybe I did not understand your answer but I try to explain better:

for example in this case http://www.voices.com/people/MichelleFalzon

"People" is the controller and "MichelleFalzon" is the resource or other parameter that is passed to the controller which then will return the resource ... I would do the same thing ....

how can I proceed side code?

#4
[eluser]pickupman[/eluser]
Yes you would do the same as the example I provided above. You are just looking a name rather than a id for a record in the DB. You will just have to make sure that a name cannot be entered twice, otherwise the second record wouldn't be accessible.

#5
[eluser]cmarra[/eluser]
Maybe I have to work with custom remap URL by URL routing?

#6
[eluser]pickupman[/eluser]
My apologies, I hadn't notice that you were giving another example with a different number of segments. You would use a route like:
Code:
$routes['people/(:any)'] = 'people/function/$1';

#7
[eluser]cmarra[/eluser]
And what would this rule?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.