[Catalyst] Calling controller/action based on parameter

bill hauck wbhauck at yahoo.com
Fri Oct 4 01:41:13 GMT 2013



=A0Hi.

I've been struggling with the best way to accomplish a somewhat simple task=
: direct to a specific controller/action based on a code in the uri.

My site is (going to be) a comprehensive entertainment database covering mo=
vies, tv shows, books, comics, graphic novels, and even games and posters. =
=A0Each media type has it's own code...

+-----+--------------------+-------------+
| id =A0| name =A0 =A0 =A0 =A0 =A0 =A0 =A0 | description |
+-----+--------------------+-------------+
| mov | Movie =A0 =A0 =A0 =A0 =A0 =A0 =A0| NULL =A0 =A0 =A0 =A0|
| tvs | TV Series =A0 =A0 =A0 =A0 =A0| NULL =A0 =A0 =A0 =A0|
| hbo | HBO =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0| NULL =A0 =A0 =A0 =A0|
| mgz | Magazine =A0 =A0 =A0 =A0 =A0 | NULL =A0 =A0 =A0 =A0|
| bok | Book =A0 =A0 =A0 =A0 =A0 =A0 =A0 | NULL =A0 =A0 =A0 =A0|
| bbd | Billboard =A0 =A0 =A0 =A0 =A0| NULL =A0 =A0 =A0 =A0|
| gcd | Greeting Card =A0 =A0 =A0| NULL =A0 =A0 =A0 =A0|
| ptr | Poster =A0 =A0 =A0 =A0 =A0 =A0 | NULL =A0 =A0 =A0 =A0|
| pcd | Post Card =A0 =A0 =A0 =A0 =A0| NULL =A0 =A0 =A0 =A0|
| web | Website =A0 =A0 =A0 =A0 =A0 =A0| NULL =A0 =A0 =A0 =A0|
| tvm | TV Movie =A0 =A0 =A0 =A0 =A0 | NULL =A0 =A0 =A0 =A0|
| stv | Straight to Video =A0| NULL =A0 =A0 =A0 =A0|
| tms | TV Miniseries =A0 =A0 =A0| NULL =A0 =A0 =A0 =A0|
| tve | TV Episode =A0 =A0 =A0 =A0 | NULL =A0 =A0 =A0 =A0|

and so on. =A0While not a "media type" I also code persons as "prn".

So my url's currently look like /media_type/id ...
Movies ...
Tron: =A0http://www.pausetosee.com/mov/movez9zbefv1fzaq
Event Horizon: =A0http://www.pausetosee.com/mov/mov1ufub4zg1mp2j

TV Episodes ...
Sons of Anarchy : The Pull: =A0http://www.pausetosee.com/tve/tve28or7cin210=
v3
Chicago Fire : A Problem House: =A0http://www.pausetosee.com/tve/tveeoz58ra=
fdccn5

Persons ...
Robert Downey Jr.: =A0http://www.pausetosee.com/person/prniffqosbaj0h2n
Ron Perlman: =A0http://www.pausetosee.com/person/prnn7ivdbdq8808p


What I'd like to do is have the system direct to the proper controller and =
action based on the 3 character code in the ID ...

Tron: =A0http://www.pausetosee.com/movez9zbefv1fzaq
Event Horizon: =A0http://www.pausetosee.com/mov1ufub4zg1mp2j

TV Episodes ...
Sons of Anarchy : The Pull: =A0http://www.pausetosee.com/tve28or7cin210v3
Chicago Fire : A Problem House: =A0http://www.pausetosee.com/tveeoz58rafdcc=
n5

Persons ...
Robert Downey Jr.: =A0http://www.pausetosee.com/prniffqosbaj0h2n
Ron Perlman: =A0http://www.pausetosee.com/prnn7ivdbdq8808p


Any suggestions on how to do this? =A0I'm toying with a large switch statem=
ent in the root controller and visiting the appropriate controller/action b=
ased on the parameter. =A0Is this right? =A0Does Catalyst provide a way to =
accomplish this either easier or cleaner?

Any help is appreciated.

Thanks,

bill
http://wbhauck.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20131003/18d8f=
de7/attachment.htm


More information about the Catalyst mailing list