quickstart-intro-mvc.xml 5.5 KB

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