SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot Rotwang's Avatar
    Join Date
    Jun 2005
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A framework that allows multiple controllers per page?

    I'm looking for a framework that allows more than one controller to handle a single request. Most frameworks tie only one controller to a url. Here is an example of what I mean,

    An "index" type of page, such as this forum's index, has pagination at the bottom. What if you wanted one page to list two forum's indexes in two separate lists with separate pagination, side by side on the page? (Or if you wanted a list of all the users on the site, paginated, and a list of all the forum posts, paginated, on the same page next to each other.)

    The page hyperlinks "page 1", "page 2", etc, would need their own namespaces, so that you could be on page 3 of list A and page 8 of list B at the same time.

    So you would need namespaces for your pagination variables. You couldn't just use "?page=1" for both lists. You would need something like:

    Code HTML4Strict:
    <a href="?lista-page=1">List A page 1</a>  <a href="?lista-page=2">List A page 2</a> <a href="?lista-page=3">List A page 3</a> 
     
    and:
     
    <a href="?listb-page=1">List B page 1</a>  <a href="?listb-page=2">List B page 2</a> <a href="?listb-page=3">List B page 3</a>

    notice the namespaces on the variables.

    The above is actually not enough, even. You would need to encapsulate the state of each list in the GET variables. For example, if you're currently viewing page 3 of list B, then the variables for list A's pagination links would be:

    Code HTML4Strict:
    <a href="?lista-page=1&listb-page=3">List A page 1</a>  <a href="?lista-page=2&listb-page=3">List A page 2</a> <a href="?lista-page=3&listb-page=3">List A page 3</a>

    Pagination is only one example of course- this applies to any GET variables that change state.

    Doing this on the session is no good- for the same old reasons- 1) because the users can't send the page URL to each other (the reason you shouldn't use session for pagination), and 2) The user could have multiple windows open...


    I've written a framework that does this- handles most of the work. The multiple controllers are in a hierarchy and their namespace is a reflection of their position in the tree.

    But I was hoping this already exists in some other php framework, (since there are so many php frameworks.) Does anyone know of this?

    The problem of using my own framework is the learning curve when I hire people. (Of course, the problem of using open frameworks is that I can't fix bugs when it goes wrong since it's not my code... Or add a feature if I need one, etc...)

    rw

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Symfony can handle this. Your template will include multiple "components", which each map to separate controllers:

    http://www.symfony-project.com/book/...yer#Components
    For instance, suppose you have a sidebar displaying the latest news headlines for a given subject, depending on the user's profile, which is reused in several pages. The queries necessary to get the news headlines are too complex to appear in a simple partial, so they need to be moved to an action-like file--a component. Figure 7-3 illustrates this example.

    For this example, shown in Listings 7-11 and 7-12, the component will be kept in its own module (called news), but you can mix components and actions in a single module if it makes sense from a functional point of view.

  3. #3
    SitePoint Zealot Rotwang's Avatar
    Join Date
    Jun 2005
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    Symfony can handle this. Your template will include multiple "components", which each map to separate controllers:

    http://www.symfony-project.com/book/...yer#Components
    That looks like it's about halfway there. That will allow multiple controllers (or "components" as they call them) from a single request. But is that going to serialized and unserialize namespaces for each component as in the pagination example above?

    That will allow the request to be passed, but it looks like the responsibility of sorting out who's variables belong to whom is left to me.

  4. #4
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    > I'm looking for a framework that allows more than one controller to handle a single
    > request.

    You are looking for a hierarchacal structure for your controllers; Forget about a chain of controllers (non hierarchacal, as it isn't flexible enough). What I had to do a while back, was as I recursed over the structure, I had already prior to the recursion, mapped the specific request parameters expected for a given controller.

    So, once I had hit upon a given controller, the recursion noted the appropriate parameters from the request, and passed those to the controller, otherwise, if there wasn't any pre-mapped parameters for this controller in question, the whole request it's self was passed instead...

    Note, that for portability, those parameters that were mapped previously, and passed to the controller as required, used a common convention in regards to their naming, so though you are talking about Page-A and Page-B for the differentiation, each controller just expected the name Page.

    Since each controller is independent of the others, this is what you want anyways; You don't therefore have the namespace clash issue since the mapping has been dealt with before you even reach the controller

  5. #5
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    However... This really is an issue with your router as I had thought about it, at the time; Is there a clean solution to route specifically to individual controllers, other than just to the dispatch alone?

    I didn't have the time to think much about it at the time, and until you posted this thread, I had forgotten about it... But I guess it's a pretty common problem huh?

  6. #6
    SitePoint Zealot Rotwang's Avatar
    Join Date
    Jun 2005
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston View Post
    >
    Since each controller is independent of the others, this is what you want anyways; You don't therefore have the namespace clash issue since the mapping has been dealt with before you even reach the controller
    We're pretty close in thinking- with my framework now, each controller is unaware of the namespaces. So, in my example, each controller is looking at it's own personal "page" variable on it's own personal input hash. That's the goal- make the framework figure which variables belong to which controller. My framework walks the controller tree and hands out input hashes based on the namespaces of the variables.

    However, there does still need to be namespacing on the $_GET variables so that the framework can do it's figuring. There would still need to be a "?lista-page=x" style url query, because there's only one GET query string on an http url.

    Am I correct that symphony won't do that for me? I'd be left to do that framework-ish job in my controllers myself.

    Still looking for a framework besides mine that can do it...

  7. #7
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    > However, there does still need to be namespacing on the $_GET variables so that the
    > framework can do it's figuring.

    That is the case and it's not something that you can avoid I've found out, so your basically stuck with it, but if we can programmatically deal with it easily then it's something we can live with.

    Not sure about Symfony myself, kind of not been keeping tabs on it for a while now.


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
  •