quickstart-intro-mvc.xml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="learning.quickstart.intro">
  4. <title>ZF &amp; MVC Introduction</title>
  5. <sect2 id="learning.quickstart.intro.zf">
  6. <title>Zend Framework</title>
  7. <para>
  8. Zend Framework is an open source, object oriented web application framework for PHP 5.
  9. ZF is often called a 'component library', because it has many loosely coupled components
  10. that you can use more or less independently. But Zend Framework also provides an
  11. advanced Model-View-Controller (MVC) implementation that can be used to establish a
  12. basic structure for your ZF applications. A full list of Zend Framework components along
  13. with short descriptions may be found in the <ulink
  14. url="http://framework.zend.com/about/components">components overview</ulink>. This
  15. QuickStart will introduce you to some of ZF's most commonly used components, including
  16. <classname>Zend_Controller</classname>, <classname>Zend_Layout</classname>,
  17. <classname>Zend_Config</classname>, <classname>Zend_Db</classname>,
  18. <classname>Zend_Db_Table</classname>, <classname>Zend_Registry</classname>, along
  19. with a few view helpers.
  20. </para>
  21. <para>
  22. Using these components, we will build a simple database-driven guest book application
  23. within minutes. The complete source code for this application is available in the
  24. following archives:
  25. </para>
  26. <itemizedlist>
  27. <listitem>
  28. <para>
  29. <ulink
  30. url="http://framework.zend.com/demos/ZendFrameworkQuickstart.zip">zip</ulink>
  31. </para>
  32. </listitem>
  33. <listitem>
  34. <para>
  35. <ulink
  36. url="http://framework.zend.com/demos/ZendFrameworkQuickstart.tar.gz">tar.gz</ulink>
  37. </para>
  38. </listitem>
  39. </itemizedlist>
  40. </sect2>
  41. <sect2 id="learning.quickstart.intro.mvc">
  42. <title>Model-View-Controller</title>
  43. <para>
  44. So what exactly is this MVC pattern everyone keeps talking about, and why should you
  45. care? MVC is much more than just a three-letter acronym (TLA) that you can whip out
  46. anytime you want to sound smart; it has become something of a standard in the design of
  47. modern web applications. And for good reason. Most web application code falls under one
  48. of the following three categories: presentation, business logic, and data access. The
  49. MVC pattern models this separation of concerns well. The end result is that your
  50. presentation code can be consolidated in one part of your application with your business
  51. logic in another and your data access code in yet another. Many developers have found
  52. this well-defined separation indispensable for keeping their code organized, especially
  53. when more than one developer is working on the same application.
  54. </para>
  55. <note>
  56. <title>More Information</title>
  57. <para>
  58. Let's break down the pattern and take a look at the individual pieces:
  59. </para>
  60. <para>
  61. <inlinegraphic width="321" scale="100" align="center" valign="middle"
  62. fileref="figures/learning.quickstart.intro.mvc.png" format="PNG" />
  63. </para>
  64. <itemizedlist>
  65. <listitem>
  66. <para>
  67. <emphasis role="strong">Model</emphasis> - This is the part of your
  68. application that defines its basic functionality behind a set of
  69. abstractions. Data access routines and some business logic can be defined in
  70. the model.
  71. </para>
  72. </listitem>
  73. <listitem>
  74. <para>
  75. <emphasis role="strong">View</emphasis> - Views define exactly what is
  76. presented to the user. Usually controllers pass data to each view to render
  77. in some format. Views will often collect data from the user, as well. This
  78. is where you're likely to find HTML markup in your MVC applications.
  79. </para>
  80. </listitem>
  81. <listitem>
  82. <para>
  83. <emphasis role="strong">Controller</emphasis> - Controllers bind the whole
  84. pattern together. They manipulate models, decide which view to display based
  85. on the user's request and other factors, pass along the data that each view
  86. will need, or hand off control to another controller entirely. Most MVC
  87. experts recommend <ulink
  88. url="http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model">keeping
  89. controllers as skinny as possible</ulink>.
  90. </para>
  91. </listitem>
  92. </itemizedlist>
  93. <para>
  94. Of course there is <ulink url="http://ootips.org/mvc-pattern.html">more to be
  95. said</ulink> about this critical pattern, but this should give you enough
  96. background to understand the guestbook application we'll be building.
  97. </para>
  98. </note>
  99. </sect2>
  100. </sect1>