Jump to content

MVC and url types?


Liquid Fire

Recommended Posts

The most common url types i see with MVC frameworks are query string(index.php?c=controller&m=method&etc...) and segment(index.php/controller/method/etc...) but i am wondering what use it is to support query string type urls?  The reason i ask is i am redesigning my php framework and i just see the point of support query string url type(most people are going to use rewrite on those type of url anyways).  The downside to using query string type urls is that there is no way to tell which variables are meant to be passed as parameters for the method call or are just part of the $_GET array.  is there any real benefit to support query string type urls that segment type urls does not have?

Link to comment
Share on other sites

  • 2 months later...

I don't think it should matter so much, nor should your framework be so tightly coupled with the way the data is coming in. You should have an implement an Interface that translates the Query String in to a data structure that you can understand down stream in your application.

 

<?php

class QueryString {
    //model object to be passed down stream
    private $controller;
    private $method;
    private $args = array();
   
    // .. get methods ..
    // .. set methods ..
}

interface QueryStringTranslationService {
    // document how toQueryString should return a QueryString Model Object
    public function toQueryString($arr);
}


class GETQueryStringTranslationServiceImpl implements QueryStringTranslationService {

    public function toQueryString($arr) {
        //arr should be passed to here by application because it has determined you've received a $_GET request in some fashion
        $qs = new QueryString();
        $qs->setController($arr['c']);
        $qs->setMethod($arr['m']);
        $qs->setArgs($arr['args']);

        return $qs;
    }

}

?>

 

The benefit of doing it this way is if there is some new trend of the month (which there always is for the web) and the URL is structured differently, you (or anyone using your framework) would be able to quickly swap out the GETQueryStringTranslationServiceImpl () for an implementation that more suits your needs.

 

This gets back to another question of yours I just answered. In my opinion, there are the types of things frameworks need to provide.

 

 

Link to comment
Share on other sites

Yea, i decided to just add it in anyways, it is just built into the url_helper and it automatically know where or not to it is a segment or query url.

 

Another question about urls that i see some frameworks do is they allow for url like:

 

www.example.com/site/index

 

automatically with an included .htaccess file.  Now if you wanted something like above in my frameowrk, by default you would have to do:

 

www.example.com/index.php/site/index

 

Do you think it is required for a framework to provide this?  My feeling is that if you want clean url(which is what that is for) that the user themselves should provide that functionality becuase i don't know what server they might be using.

Link to comment
Share on other sites

 

Do you think it is required for a framework to provide this?  My feeling is that if you want clean url(which is what that is for) that the user themselves should provide that functionality becuase i don't know what server they might be using.

 

 

That is the best assumption to make -- You cannot make assumptions :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.