quickstart-intro-mvc.xml 5.7 KB

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