Zend Framework 2. MVC Tricode Professional Services www.tricode.nl Date: 20-02-2009 Author: Marcel Blok
MVC Pattern Model-view-controller pattern “ The Model-View-Controller (MVC) pattern separates the modeling of the domain, the presentation, and the actions based on user input into three separate classes”
MVC Pattern The Model The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the View), and responds to instructions to change state (usually from the Controller).
MVC Pattern The View The Controller interprets the input from the user, informing the Model and/or the View to change as appropriate.
MVC Pattern The Controller The Controller interprets the input from the user, informing the Model and/or the View to change as appropriate.
MVC Pattern Advantages High cohesion Easy to extend Clear structure More easy to create automatic tests (like unit-tests) Etc.
ZF MVC The basic Zend Framework workflow of handling a request is fairly simple.
ZF MVC First the Request is ‘captured’ and a Request Object is made. The Request Object is just a representation of the Request itself. By default the HTTP Request Object is used. It holds attributes like the URL and parameters.
ZF MVC Secondly the Router is called. The Router checks the Request Object, and alters it depending on registered Routes. By default the Rewrite Router is used. This Router sets the controller, action and parameters from the URL.
ZF MVC After the Routing is done, the Dispatch Loop is started. The Dispatch Loop is performed until the status of the Request Object is set to ‘dispatched’.
ZF MVC The default Dispatcher is the Standard Dispatcher. This Dispatcher defines controllers as UpperCamelCase classes that end with Controller, and derfines actions as lowerCamelCase methods ending with Action. FooController::barAction()
ZF MVC Next, the Action Controller is called. This is the Controller that you have created yourself. Like this: /foo/bar FooController::barAction()
ZF MVC The Action Controller often implements a View. As the View is rendered, the output is added to the Response Object.
ZF MVC After the Action Controller has finished the Dispatcher Loop normally finishes. If the Action Controller resetted the Dispatched status of the Request Object, the Loop continues, and a new Dispatch is triggered. For instance you can forward to another Action.
ZF MVC At last the Response is sent back. By default the Response used is the http Response.
Auto loading PHP5 supports autoloading through the __autoload() function From PHP 5.1.2 spl_autoload() is also supported
Auto loading Zend Framework supports auto loading. A file contains 1 class. The classname resembles the name and location of the file. Zend_My_Class staat in Zend/My/Class.php
Where do I find it? Project application -- module -- -- controllers -- -- data -- -- layouts -- -- models -- -- views -- -- -- scripts library -- Zend public test

Zend framework 02 - mvc

  • 1.
    Zend Framework 2.MVC Tricode Professional Services www.tricode.nl Date: 20-02-2009 Author: Marcel Blok
  • 2.
    MVC Pattern Model-view-controllerpattern “ The Model-View-Controller (MVC) pattern separates the modeling of the domain, the presentation, and the actions based on user input into three separate classes”
  • 3.
    MVC Pattern TheModel The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the View), and responds to instructions to change state (usually from the Controller).
  • 4.
    MVC Pattern TheView The Controller interprets the input from the user, informing the Model and/or the View to change as appropriate.
  • 5.
    MVC Pattern TheController The Controller interprets the input from the user, informing the Model and/or the View to change as appropriate.
  • 6.
    MVC Pattern AdvantagesHigh cohesion Easy to extend Clear structure More easy to create automatic tests (like unit-tests) Etc.
  • 7.
    ZF MVC Thebasic Zend Framework workflow of handling a request is fairly simple.
  • 8.
    ZF MVC Firstthe Request is ‘captured’ and a Request Object is made. The Request Object is just a representation of the Request itself. By default the HTTP Request Object is used. It holds attributes like the URL and parameters.
  • 9.
    ZF MVC Secondlythe Router is called. The Router checks the Request Object, and alters it depending on registered Routes. By default the Rewrite Router is used. This Router sets the controller, action and parameters from the URL.
  • 10.
    ZF MVC Afterthe Routing is done, the Dispatch Loop is started. The Dispatch Loop is performed until the status of the Request Object is set to ‘dispatched’.
  • 11.
    ZF MVC Thedefault Dispatcher is the Standard Dispatcher. This Dispatcher defines controllers as UpperCamelCase classes that end with Controller, and derfines actions as lowerCamelCase methods ending with Action. FooController::barAction()
  • 12.
    ZF MVC Next,the Action Controller is called. This is the Controller that you have created yourself. Like this: /foo/bar FooController::barAction()
  • 13.
    ZF MVC TheAction Controller often implements a View. As the View is rendered, the output is added to the Response Object.
  • 14.
    ZF MVC Afterthe Action Controller has finished the Dispatcher Loop normally finishes. If the Action Controller resetted the Dispatched status of the Request Object, the Loop continues, and a new Dispatch is triggered. For instance you can forward to another Action.
  • 15.
    ZF MVC Atlast the Response is sent back. By default the Response used is the http Response.
  • 16.
    Auto loading PHP5supports autoloading through the __autoload() function From PHP 5.1.2 spl_autoload() is also supported
  • 17.
    Auto loading ZendFramework supports auto loading. A file contains 1 class. The classname resembles the name and location of the file. Zend_My_Class staat in Zend/My/Class.php
  • 18.
    Where do Ifind it? Project application -- module -- -- controllers -- -- data -- -- layouts -- -- models -- -- views -- -- -- scripts library -- Zend public test