Place Directory URLs: Route or Remap?

#1
[eluser]kirkaracha[/eluser]
I'm working on an application that lists places, primarily US cities with a few international locations.

I'd like the URLs to work like this:

/places/ <- intro text and search form
/places/ohio/ <- list of cities in Ohio
/places/ohio/cincinnati/ <- place info for Cincinnati
/places/england/<- list of cities in England
/places/england/london/ <- place info for London
/places/add/ <- form for adding places
/places/edit/1/ <- form for editing places
/places/delete/1/ <- form for deleting places

What's the best way to set this up?

I've started with routes but I'm having trouble figuring out how to handle having the second URL segment.

Could set up routes for add/edit/delete, then remap everything else though the index function?

#2
[eluser]designfellow[/eluser]
Hi,

You can easily remap all functions except add,edit, delete thru index.php

or you can direct all the requests to a custom function which redirects them to appropriate functions

eg.

function remap_it()
{
if(!$this->uri->segment(4))
{
// do some switch conditions & redirect them to state main pages
}
else
{
// do some matching and redirect to particular sub pages
}
}





Happy Coding,
DesignFellow

#3
[eluser]jedd[/eluser]
You don't say if there's a bunch of other controllers you have to contend with? Are add, edit, etc - controllers, or functions within a management controller? Are the countries displayed by a country controller, or is everything under one big controller?

Aside: what's with the fixation the US has of not having its country (code) listed on anything to do with the Internet? Is it an attempt to recover some ground against the Brits for being first to claim the right of not needing to have their country on stamps and currency? It seems like a number of your problems would be resolved by treating countries consistently.

#4
[eluser]Phil Sturgeon[/eluser]
Routes

Code:
$route['places/add'] = 'places/add';
$route['places/edit/:num'] = 'places/edit/$1';
$route['places/delete/:num'] = 'places/delete/$1';
$route['places/:any'] = 'places/country_details/$1';
$route['places/:any/:any'] = 'places/city_details/$1/$2';

Controller skelton

Code:
class Places extends Controller {

function index() {}

function country_details($country) {}

function city_details($country, $city) {}

function add() {}

function edit($id) {}

function delete($id) {}

}

Tada!

#5
[eluser]fesweb[/eluser]
Hi,
If it's not too late, you should probably avoid routes if you can.

Remap the controller this way:
Code:
function _remap($method)
    {
        if (method_exists($this, $method))
        {
            $this->$method();
        }
        else
        {
            $this->handler();
        }
    }

function handler()
       {
             // do whatever you need to do here
             $this->my_library->get_stuff($this->uri->segment(2), $this->uri->segment(3));
       }
function add() { // add code }
function edit() { // edit code }
function delete() { // delete code }
Something like that should do it.

Good luck.

#6
[eluser]fesweb[/eluser]
Important!

If you follow my advice, your handler should absolutely include some kind of 404 error handling to prevent search bot black holes...


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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