SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast traxxas's Avatar
    Join Date
    Jan 2007
    Location
    San Diego, CA
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Controller has grown too complex

    A bit of background info:
    I maintain and develop an ecommerce site that I inherited with a mashup of dynamic and static content spanning 3 different developers. The products carried are varied in that each product section is its own web app because navigating the user through the options varies section to section.

    The problem:
    The sections I have developed use a very simple non OOP MVC. I mod_rewrite everything to my front controller, parse the url, and a case statement includes the model and associated view. It has worked out well for me thus far. In developing new sections and converting static sections to dynamic sections I have added some helper functions like auto thumbnails with caching and front office specialized views. Now my controllers have grown into unwieldy nests of code. Basically my controller is handling 3 methods of selecting models/views
    1. Commands - eg. imgresize.100/{imgpath}/
    2. URI size - eg. /{cat/, /{cat}/{type}/, /{cat}/{type}/{color}/, etc
    3. Standard html pages that are just content eg. disclaimers, shipping info, etc

    I know its time to refactor but don't know where to start. Is this too much for a controller to handle efficiently? Or is it that my url structure has grown too complex to implement gracefully in the MVC pattern? After some reading of codeignigter's manual they have a bit about url design, are there any good references on this subject?

  2. #2
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by traxxas View Post
    A bit of background info:
    I maintain and develop an ecommerce site that I inherited with a mashup of dynamic and static content spanning 3 different developers. The products carried are varied in that each product section is its own web app because navigating the user through the options varies section to section.

    The problem:
    The sections I have developed use a very simple non OOP MVC. I mod_rewrite everything to my front controller, parse the url, and a case statement includes the model and associated view. It has worked out well for me thus far. In developing new sections and converting static sections to dynamic sections I have added some helper functions like auto thumbnails with caching and front office specialized views. Now my controllers have grown into unwieldy nests of code. Basically my controller is handling 3 methods of selecting models/views
    1. Commands - eg. imgresize.100/{imgpath}/
    2. URI size - eg. /{cat/, /{cat}/{type}/, /{cat}/{type}/{color}/, etc
    3. Standard html pages that are just content eg. disclaimers, shipping info, etc

    I know its time to refactor but don't know where to start. Is this too much for a controller to handle efficiently? Or is it that my url structure has grown too complex to implement gracefully in the MVC pattern? After some reading of codeignigter's manual they have a bit about url design, are there any good references on this subject?
    In your case, I would consider using a chain of controllers to seperate the differences you have in the selection process.

    Check out this thread (it's quite a long one) - there is some example code in there where a FilterChain is implemented which should give you some ideas:

    http://www.sitepoint.com/forums/showthread.php?t=271112

    HTH,

    Dan

  3. #3
    SitePoint Guru
    Join Date
    May 2005
    Location
    Finland
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why is your Controller checking the URL directly anyway? How about you separate that bit of functionality in a Router that maps the URL into parameters for the Controller.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •