Welcome Guest, Not a member yet? Register   Sign In
Invoking a subset within a CI application
#12

[eluser]Colin Williams[/eluser]
Quote:How does one implement the logic to handle a URL such as

One reads the User Guide and learns that the URI class has magical functions like uri_to_assoc()

Quote:Which controller or controllers need to be written receive the URL?

Well, if you're being RESTful, you need to think about what your Resources are, and have a controller for each. To me, it looks like the resource is actually Programs. Season is just a parameter, like team or grade.

Quote:I tried adding the following line to my routes.php file, but when I then invoke the URL above, instead of getting the 404 page I just get a blank page!
Code:
$route['season/(:any)/program/(:any)/team/:any')] = 'team/info/$1_$2_$3'

Couple of things.

First of all, there is a glaring syntax error there.

Second, this route says that you have a Team controller with a function "info." Is this correct? You should probably have a Program controller, with the index function handling the, er, indexing. Or, Teams may very well be a resource. In this case, I would consider a more appropriate URI, like /team/14/season/2009/grade/10. A good rule of thumb to follow is /resource/action/guid/params. When you starting doing, /params/params/resource/guid, routing becomes more of a headache.

Third, all you need to settle for the URI to be routed is the controller and the function. Doing param/match/param/match/... is woefully rigid. A route as follows is more appropriate.

Code:
$route['season/(.*)'] = "program/index/season/$1";

This means /season/2009/team/buccaneers gets routed to /program/index/season/2009/team/buccaneers and /season/2009/team/buccaneers/grade/10/fname/steve gets routed to /program/index/season/2009/team/buccaneers/grade/10/fname/steve. And then, with uri_to_assoc(), you get an array like

Code:
array(
  'season' => '2009',
  'team' => 'buccaneers',
  'grade' => '10',
  'fname' => 'steve',
);

... which you can use when querying the records. Again, consider doing /program/index/season/2009 and kiss the need for routing goodbye. Hope I've covered it...

(And also, it's frustrating to see--still, at this day and age--so much misconception about REST.. POSTing hidden fields to GET resources!? Eh!? Multiple URIs for a single resource/result set!? Eh!?)


Messages In This Thread
Invoking a subset within a CI application - by El Forum - 06-13-2009, 04:35 PM
Invoking a subset within a CI application - by El Forum - 06-13-2009, 06:26 PM
Invoking a subset within a CI application - by El Forum - 06-13-2009, 06:29 PM
Invoking a subset within a CI application - by El Forum - 06-13-2009, 06:43 PM
Invoking a subset within a CI application - by El Forum - 06-13-2009, 07:00 PM
Invoking a subset within a CI application - by El Forum - 06-13-2009, 07:05 PM
Invoking a subset within a CI application - by El Forum - 06-13-2009, 07:29 PM
Invoking a subset within a CI application - by El Forum - 06-13-2009, 07:40 PM
Invoking a subset within a CI application - by El Forum - 06-13-2009, 08:02 PM
Invoking a subset within a CI application - by El Forum - 07-03-2009, 11:47 AM
Invoking a subset within a CI application - by El Forum - 07-03-2009, 01:06 PM
Invoking a subset within a CI application - by El Forum - 07-03-2009, 01:33 PM
Invoking a subset within a CI application - by El Forum - 07-03-2009, 03:26 PM



Theme © iAndrew 2016 - Forum software by © MyBB