SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 30 of 30
  1. #26
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,149
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    http://www.google.com/doesnt-exist

    Would it -- should it? -- matter if this 404 was generated because the server couldn't find a file or because a script couldn't find a route?

    EDIT: A couple other examples.

    https://profiles.google.com/doesnt-exist
    http://www.facebook.com/reallydoesntexist

    Under the hood, it's possible that this is being rewritten to facebook.com/profile.php?slug=reallydoesntexist, but that shouldn't matter. What matters is whether the resource identified by the URL is available. If not, then a 404 Not Found is absolutely the correct response.
    "First make it work. Then make it better."

  2. #27
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,011
    Mentioned
    56 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    If you ask me, that isn't a 404. That is validating your input.
    uhm...

    Quote Originally Posted by Jeff Mott View Post
    Regardless if we call it validation, ultimately we're testing whether the resource identified by a URL can be found..
    @cpradio, you can't split the hair here to keep your original statement correct. A URI request is input to your server. The HTTP protocol calls on the client to, at a minimum, specify a URI and a request type (usually GET or POST). The rewrite module effectively relays this task from Apache to PHP. (what it actually does is rewrite the URI, then redirect it to the new resource target, usually index.php of the directory where the resource was requested from).

    The moment the PHP script is tasked with processing the URI to find "pages" that it dynamically generates, it must also have programming to return error codes appropriate to the validation errors it encounters - most frequently 404.

    Getting back to my original proposal, what I'm looking for is a PHP form structure that can facilitate this common use case - specifically to this end: PHP is able to write snippets of itself for further evalutation. Consider a CMS system's home page. For a lot of customers I've built CMS's for their home page remains static for days and weeks at a time. My custom CMS takes advantage of this by writing a static version of the page into the ./htdocs directory. Apache can then hit that static cache and load the page without any PHP or database. It's incredibly fast and stable. That cache page is dropped whenever anyone edits it in the admin panel. A more advanced version lets that replacement be set on a timer, so the PHP static snippet quickly does a time check and if necessarily the db gets called up and the page gets built only once dynamically.

    My next framework is a more intricate version of this concept allowing block areas of the page to update.

    Because of how mod-rewrite works I have to have at least 1 php file in the directory. To that end I have __landing__.php as a "magic" file on the root to process the php requests. I'd rather be rid of even that. Doing that will require something core to PHP. To that end I'm considering what kind of fundamental router could be introduced that would be useful across frameworks.

    Would it be useable out of the box like PDO? Not likely - routing rules are vastly different between frameworks. Can a fundemental "simple" routing schema be introduced that most projects would be happy with and be embedded into the default. I think that is possible. Explaining it out will take a much longer post than I have time to write at the moment.

  3. #28
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    988
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    I don't think a "router" itself does enough on its own to warrant a PDO style class. I mean, my router class looks like this:

    PHP Code:

    interface RouterRule {
        public function 
    find(array $route);
    }

    class 
    Router {
        private 
    $rules = array();
        
        public function 
    addRule(RouterRule $rule$highPriority false) {
            if (
    $highPriorityarray_unshift($this->rules$rule);
            else 
    $this->rules[] = $rule;
        }
        
        public function 
    getRoute(array $route) {
            foreach (
    $this->rules as $rule) {
                if (
    $found $rule->find($route)) return $found;    
            }
            
            throw new 
    Exception('No matching route found');
        }

    All the framework (or even application) specific stuff is handled by rules. And these aren't going to be repeatable.... I just don't see how something as trivial as the generic router class is complex enough to need standardisation.

  4. #29
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,079
    Mentioned
    53 Post(s)
    Tagged
    0 Thread(s)
    While I don't think I'm ready to play ball on this thread, I would like to throw in this tid bit:

    I think a PHP framework / front controller should allow for seamless use of the same classes / resources on the CLI side as the web side, without any modification.

  5. #30
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,576
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    I think there is a big structural flaw with doing this within PHP -- the whole shared nothing / no persistent application server running makes having something like a non-trivial routing engine very, very expensive so fobbing it off on Apache and mod_rewrite wins. Why bother with this when you could go pick up something like flask (python) or sinatra (ruby) and not have to deal with this and still stay in a comfortableish scripting environment.


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
  •