SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 28 of 28
  1. #26
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,147
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    PHP isn't event driven so the way around a typical MVC approach in a event driven paradigm is to have the controller move information from the model to the view. In a event driven application the view would read directly from the model though. The view would essentially listen for a update event of some kind on the model. When the model dispatched that event the view would then update and read the appropriate information from the view. However, this isn't really possible in PHP. Instead the Ruby Approach has been adopted and coined MVC for the non event driven applications like those of the internet putting aside flash apps.

  2. #27
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,023
    Mentioned
    63 Post(s)
    Tagged
    0 Thread(s)
    extract() is the coolest function in PHP. Here's my entire template engine

    PHP Code:
        protected function parse($template$output null) {
            if (empty(
    $output)) {
                
    $this->preParse();
                
    $output $this->output;
            }
            
            
    extract($output);
            
            
    ob_start();
            include(
    $this->findTemplate($template));    
            
    $this->parsedOutput .= ob_get_clean();
            
        }
        
        
    /**
         * Preparse - allows us to one last chance to manipulate output arrays 
         * before they are fed into the view files. This function does nothing 
         * at this level - override it as necessary.
         */
        
    protected function preParse() {} 
    This is all part of the root controller class. The controller does it's thing - calling up relevant models, getting data reports from them, and puts it all in the $output member of the controller. The view gets included into the parse function, the output is extracted to the current scope, then the view code runs.

    View code is PHP, though I do use braceless syntax in the views. Again, as others have stated, self-discipline is used to make sure database calls and the like don't occur in the view.

    Preparse exists for polymorphic reasons - I've used it once in the framework's history. Parse can also be given output to parse rather than use the output of the current controller - this allows one controller to call another.

    Obviously this is a LOT less overhead than smarty or any of the other Template engines. In my opinion putting a template engine in PHP is like using a pickup truck to pull a semi-truck - unwieldy and wasteful at best.

    Further, if I wanted a language that needed a separate template engine for enforcing business logic segregation from view logic I'd use Python or Java as both of these solutions will be faster and more efficient than PHP in that situation. Using a template engine with PHP butchers the very advantages PHP brings to the table - if code segregation is that important than use a language that facilitates it and works well under that constraint. PHP is not such a language.

  3. #28
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,023
    Mentioned
    63 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by oddz View Post
    PHP isn't event driven so the way around a typical MVC approach in a event driven paradigm is to have the controller move information from the model to the view. In a event driven application the view would read directly from the model though. The view would essentially listen for a update event of some kind on the model. When the model dispatched that event the view would then update and read the appropriate information from the view. However, this isn't really possible in PHP. Instead the Ruby Approach has been adopted and coined MVC for the non event driven applications like those of the internet putting aside flash apps.
    Didn't spot this earlier. True, PHP isn't event driven, but Javascript is. If javascript handlers are attached to AJAX requesters they can be resolved to specific functions in PHP which in turn can behave as 'events'. They can compose their responses as javascript.

    My framework is built around this concept - a sort of MVC^2 since there are two controllers (one in PHP and one in JS). Ruby influences it some since I've chosen the prototype framework for the js side of things.


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
  •