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>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. This QuickStart will introduce you to some of Zend Framework's most commonly used components,
  14. including <classname>Zend_Controller</classname>, <classname>Zend_Layout</classname>,
  15. <classname>Zend_Config</classname>, <classname>Zend_Db</classname>,
  16. <classname>Zend_Db_Table</classname>, <classname>Zend_Registry</classname>, along
  17. with a few view helpers.
  18. </para>
  19. <para>
  20. Using these components, we will build a simple database-driven guest book application
  21. within minutes. The complete source code for this application is available in the
  22. following archives:
  23. </para>
  24. <itemizedlist>
  25. <listitem>
  26. <para>
  27. <ulink
  28. url="http://framework.zend.com/demos/ZendFrameworkQuickstart.zip">zip</ulink>
  29. </para>
  30. </listitem>
  31. <listitem>
  32. <para>
  33. <ulink
  34. url="http://framework.zend.com/demos/ZendFrameworkQuickstart.tar.gz">tar.gz</ulink>
  35. </para>
  36. </listitem>
  37. </itemizedlist>
  38. </sect2>
  39. <sect2 id="learning.quickstart.intro.mvc">
  40. <title>Model-View-Controller</title>
  41. <para>
  42. So what exactly is this <acronym>MVC</acronym> pattern everyone keeps talking about, and
  43. why should you care? <acronym>MVC</acronym> is much more than just a three-letter
  44. acronym (<acronym>TLA</acronym>) that you can whip out anytime you want to sound smart;
  45. it has become something of a standard in the design of modern web applications. And for
  46. good reason. Most web application code falls under one of the following three
  47. categories: presentation, business logic, and data access. The <acronym>MVC</acronym>
  48. pattern models this separation of concerns well. The end result is that your
  49. presentation code can be consolidated in one part of your application with your business
  50. logic in another and your data access code in yet another. Many developers have found
  51. this well-defined separation indispensable for keeping their code organized, especially
  52. when more than one developer is working on the same application.
  53. </para>
  54. <note>
  55. <title>More Information</title>
  56. <para>
  57. Let's break down the pattern and take a look at the individual pieces:
  58. </para>
  59. <para>
  60. <inlinegraphic width="321" scale="100" align="center" valign="middle"
  61. fileref="figures/learning.quickstart.intro.mvc.png" format="PNG" />
  62. </para>
  63. <itemizedlist>
  64. <listitem>
  65. <para>
  66. <emphasis>Model</emphasis> - This is the part of your
  67. application that defines its basic functionality behind a set of
  68. abstractions. Data access routines and some business logic can be defined in
  69. the model.
  70. </para>
  71. </listitem>
  72. <listitem>
  73. <para>
  74. <emphasis>View</emphasis> - Views define exactly what is
  75. presented to the user. Usually controllers pass data to each view to render
  76. in some format. Views will often collect data from the user, as well. This
  77. is where you're likely to find <acronym>HTML</acronym> markup in your
  78. <acronym>MVC</acronym> applications.
  79. </para>
  80. </listitem>
  81. <listitem>
  82. <para>
  83. <emphasis>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
  87. <acronym>MVC</acronym> 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>