SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    May 2003
    Location
    virginia
    Posts
    988
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Front Controller - How to handle link hrefs

    I have a FrontController that is simply getting a page controller based on a URL param called "page". Depending on the server we use one of the following:

    $_SERVER['PATH_INFO'] -> /index.php/page/about
    $_GET -> /index.php?page=about

    I'd like to know a simple way of handling a situation where we've built the site, say in Dreamweaver using the $_GET scheme, but then it changes and we want to go with the PATH_INFO style.

    I have a request factory class that returns a request object, that can handle the two types, using the same request interface. It's passed down to the page controllers (FrontController->RequestMapper->PageController). So that's handled. It's the HTML that is a problem.

    I was thinking I could add a method to the request class called url() that would return a specialized type of url object, that would know how to build the urls (like the Eclipse Url class)?

    $url =& $request->url();
    $url->setBasename('/index.php')
    $url->setParam('page', 'about');
    echo $url->getLink('About');

    Of course that's not good for a template so I'd need to figure out a nice short implementation:

    <pageLink path="products/home">About</pageLink>.

    Maybe I'm making this too complicated already. Does anyone understand what I'm trying to achieve? Is this the right way to handle url styles that could possibly change? I know a little about ModRewrite but that won't help us from having to go back and change the HTML a href attributes, or will it?

    Matt

  2. #2
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I prefer to assign PATH_INFO to the request array or specifically to the "action" parameter inside the Request class. Then all you have to do is either change action param name, or do nothing and it just works.
    Christopher

  3. #3
    SitePoint Guru
    Join Date
    May 2003
    Location
    virginia
    Posts
    988
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see. So you merge the values?

    What about the fact that you can sometimes get away with doing things like:

    /index.php/var1/
    /index/var1/
    /var1/

    Depending on Apache's settings, they all have their little differences.

    I'd like to find a way to make the html links that are written in the templates/content files, somewhat generic.

    Thanks for you input.

    Matt

  4. #4
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'll need some sort of url-mapping object. Putting it in the request seems wrong to me. It's an application-global like the request, but that's all they have in common. If you pass your request within a context-object, you could put the url-mapper in there too.

    PHP Code:
    <?=$context->url(Array('page' => 'about'))?>
    <?=$context
    ->url(Array('page' => 'about''var' => '1'))?>


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
  •