Zend_View-Helpers-Navigation.xml 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect3 id="zend.view.helpers.initial.navigation">
  4. <title>Navigation Helpers</title>
  5. <para>
  6. The navigation helpers are used for rendering navigational elements
  7. from <link linkend="zend.navigation.containers">Zend_Navigation_Container</link>
  8. instances.
  9. </para>
  10. <para>
  11. There are 5 built-in helpers:
  12. </para>
  13. <itemizedlist>
  14. <listitem>
  15. <para>
  16. <link
  17. linkend="zend.view.helpers.initial.navigation.breadcrumbs">Breadcrumbs</link>,
  18. used for rendering the path to the currently active page.
  19. </para>
  20. </listitem>
  21. <listitem>
  22. <para>
  23. <link linkend="zend.view.helpers.initial.navigation.links">Links</link>,
  24. used for rendering navigational head links (e.g.
  25. <command>&lt;link rel="next" href="..." /&gt;</command>)
  26. </para>
  27. </listitem>
  28. <listitem>
  29. <para>
  30. <link linkend="zend.view.helpers.initial.navigation.menu">Menu</link>,
  31. used for rendering menus.
  32. </para>
  33. </listitem>
  34. <listitem>
  35. <para>
  36. <link linkend="zend.view.helpers.initial.navigation.sitemap">Sitemap</link>,
  37. used for rendering sitemaps conforming to the <ulink
  38. url="http://www.sitemaps.org/protocol.php">Sitemaps <acronym>XML</acronym>
  39. format</ulink>.
  40. </para>
  41. </listitem>
  42. <listitem>
  43. <para>
  44. <link
  45. linkend="zend.view.helpers.initial.navigation.navigation">Navigation</link>,
  46. used for proxying calls to other navigational helpers.
  47. </para>
  48. </listitem>
  49. </itemizedlist>
  50. <para>
  51. All built-in helpers extend
  52. <classname>Zend_View_Helper_Navigation_HelperAbstract</classname>, which
  53. adds integration with <link linkend="zend.acl">ACL</link> and
  54. <link linkend="zend.translate">translation</link>. The abstract class
  55. implements the interface
  56. <classname>Zend_View_Helper_Navigation_Helper</classname>, which
  57. defines the following methods:
  58. </para>
  59. <itemizedlist>
  60. <listitem>
  61. <para>
  62. <methodname>getContainer()</methodname> and <methodname>setContainer()</methodname>
  63. gets and sets the navigation container the helper should operate on by default, and
  64. <methodname>hasContainer()</methodname> checks if the helper
  65. has container registered.
  66. </para>
  67. </listitem>
  68. <listitem>
  69. <para>
  70. <methodname>getTranslator()</methodname> and
  71. <methodname>setTranslator()</methodname> gets and sets the
  72. translator used for translating labels and titles.
  73. <methodname>getUseTranslator()</methodname> and
  74. <methodname>setUseTranslator()</methodname> controls whether
  75. the translator should be enabled. The method
  76. <methodname>hasTranslator()</methodname> checks if the helper has
  77. a translator registered.
  78. </para>
  79. </listitem>
  80. <listitem>
  81. <para>
  82. <methodname>getAcl()</methodname>, <methodname>setAcl()</methodname>,
  83. <methodname>getRole()</methodname> and <methodname>setRole()</methodname>,
  84. gets and sets <acronym>ACL</acronym> (<classname>Zend_Acl</classname>) instance and
  85. role (<type>String</type> or
  86. <classname>Zend_Acl_Role_Interface</classname>) used for
  87. filtering out pages when rendering. <methodname>getUseAcl()</methodname> and
  88. <methodname>setUseAcl()</methodname> controls whether <acronym>ACL</acronym> should
  89. be enabled. The methods <methodname>hasAcl()</methodname> and
  90. <methodname>hasRole()</methodname> checks if the helper has an
  91. <acronym>ACL</acronym> instance or a role registered.
  92. </para>
  93. </listitem>
  94. <listitem>
  95. <para>
  96. <methodname>__toString()</methodname>, magic method to ensure that
  97. helpers can be rendered by echoing the helper instance directly.
  98. </para>
  99. </listitem>
  100. <listitem>
  101. <para>
  102. <methodname>render()</methodname>, must be implemented by concrete
  103. helpers to do the actual rendering.
  104. </para>
  105. </listitem>
  106. </itemizedlist>
  107. <para>
  108. In addition to the method stubs from the interface, the abstract
  109. class also implements the following methods:
  110. </para>
  111. <itemizedlist>
  112. <listitem>
  113. <para>
  114. <methodname>getIndent()</methodname> and <methodname>setIndent()</methodname>
  115. gets and sets indentation. The setter accepts a <type>String</type> or an
  116. <type>Integer</type>. In the case of an <type>Integer</type>, the helper will use
  117. the given number of spaces for indentation. I.e.,
  118. <methodname>setIndent(4)</methodname> means 4 initial spaces of
  119. indentation. Indentation can be specified for all helpers
  120. except the Sitemap helper.
  121. </para>
  122. </listitem>
  123. <listitem>
  124. <para>
  125. <methodname>getMinDepth()</methodname> and <methodname>setMinDepth()</methodname>
  126. gets and sets the minimum depth a page must have to be included by the helper.
  127. Setting <constant>NULL</constant> means no minimum depth.
  128. </para>
  129. </listitem>
  130. <listitem>
  131. <para>
  132. <methodname>getMaxDepth()</methodname> and <methodname>setMaxDepth()</methodname>
  133. gets and sets the maximum depth a page can have to be included by the helper.
  134. Setting <constant>NULL</constant> means no maximum depth.
  135. </para>
  136. </listitem>
  137. <listitem>
  138. <para>
  139. <methodname>getRenderInvisible()</methodname> and
  140. <methodname>setRenderInvisible()</methodname> gets and sets whether to
  141. render items that have been marked as invisible or not.
  142. </para>
  143. </listitem>
  144. <listitem>
  145. <para>
  146. <methodname>__call()</methodname> is used for proxying calls to the
  147. container registered in the helper, which means you can
  148. call methods on a helper as if it was a container. See <link
  149. linkend="zend.view.helpers.initial.navigation.proxy.example">example</link>
  150. below.
  151. </para>
  152. </listitem>
  153. <listitem>
  154. <para>
  155. <methodname>findActive($container, $minDepth, $maxDepth)</methodname>
  156. is used for finding the deepest active page in the given
  157. container. If depths are not given, the method will use
  158. the values retrieved from <methodname>getMinDepth()</methodname> and
  159. <methodname>getMaxDepth()</methodname>. The deepest active page must
  160. be between <varname>$minDepth</varname> and <varname>$maxDepth</varname>
  161. inclusively. Returns an array containing a reference to the
  162. found page instance and the depth at which the page was
  163. found.
  164. </para>
  165. </listitem>
  166. <listitem>
  167. <para>
  168. <methodname>htmlify()</methodname> renders an <emphasis>'a'</emphasis>
  169. <acronym>HTML</acronym> element from a <classname>Zend_Navigation_Page</classname>
  170. instance.
  171. </para>
  172. </listitem>
  173. <listitem>
  174. <para>
  175. <methodname>accept()</methodname> is used for determining if a page
  176. should be accepted when iterating containers. This method
  177. checks for page visibility and verifies that the helper's
  178. role is allowed access to the page's resource and privilege.
  179. </para>
  180. </listitem>
  181. <listitem>
  182. <para>
  183. The static method <methodname>setDefaultAcl()</methodname> is used for setting
  184. a default <acronym>ACL</acronym> object that will be used by helpers.
  185. </para>
  186. </listitem>
  187. <listitem>
  188. <para>
  189. The static method <methodname>setDefaultRole()</methodname> is used for setting
  190. a default <acronym>ACL</acronym> that will be used by helpers
  191. </para>
  192. </listitem>
  193. </itemizedlist>
  194. <para>
  195. If a navigation container is not explicitly set in a helper using
  196. <command>$helper->setContainer($nav)</command>, the helper will look
  197. for a container instance with the key <classname>Zend_Navigation</classname> in
  198. <link linkend="zend.registry">the registry</link>.
  199. If a container is not explicitly set or found in the registry, the
  200. helper will create an empty <classname>Zend_Navigation</classname>
  201. container when calling <command>$helper->getContainer()</command>.
  202. </para>
  203. <example id="zend.view.helpers.initial.navigation.proxy.example">
  204. <title>Proxying calls to the navigation container</title>
  205. <para>
  206. Navigation view helpers use the magic method <methodname>__call()</methodname>
  207. to proxy method calls to the navigation container that is
  208. registered in the view helper.
  209. </para>
  210. <programlisting language="php"><![CDATA[
  211. $this->navigation()->addPage(array(
  212. 'type' => 'uri',
  213. 'label' => 'New page'));
  214. ]]></programlisting>
  215. <para>
  216. The call above will add a page to the container in the
  217. <classname>Navigation</classname> helper.
  218. </para>
  219. </example>
  220. <sect4 id="zend.view.helpers.initial.navigation.i18n">
  221. <title>Translation of labels and titles</title>
  222. <para>
  223. The navigation helpers support translation of page labels and titles.
  224. You can set a translator of type <classname>Zend_Translate</classname>
  225. or <classname>Zend_Translate_Adapter</classname> in the helper using
  226. <command>$helper->setTranslator($translator)</command>, or like with other
  227. I18n-enabled components; by adding the translator to
  228. <link linkend="zend.registry">the registry</link> by using the key
  229. <classname>Zend_Translate</classname>.
  230. </para>
  231. <para>
  232. If you want to disable translation, use
  233. <command>$helper->setUseTranslator(false)</command>.
  234. </para>
  235. <para>
  236. The
  237. <link linkend="zend.view.helpers.initial.navigation.navigation">proxy
  238. helper</link> will inject its own translator to the helper it
  239. proxies to if the proxied helper doesn't already have a translator.
  240. </para>
  241. <note>
  242. <para>
  243. There is no translation in the sitemap helper, since there
  244. are no page labels or titles involved in an <acronym>XML</acronym> sitemap.
  245. </para>
  246. </note>
  247. </sect4>
  248. <sect4 id="zend.view.helpers.initial.navigation.acl">
  249. <title>Integration with ACL</title>
  250. <para>
  251. All navigational view helpers support <acronym>ACL</acronym> inherently from the
  252. class <classname>Zend_View_Helper_Navigation_HelperAbstract</classname>.
  253. A <classname>Zend_Acl</classname> object can be assigned to
  254. a helper instance with <code>$helper->setAcl($acl)</code>, and role
  255. with <code>$helper->setRole('member')</code> or
  256. <code>$helper->setRole(new Zend_Acl_Role('member'))</code> . If <acronym>ACL</acronym>
  257. is used in the helper, the role in the helper must be allowed by
  258. the <acronym>ACL</acronym> to access a page's <code>resource</code> and/or have the
  259. page's <code>privilege</code> for the page to be included when
  260. rendering.
  261. </para>
  262. <para>
  263. If a page is not accepted by <acronym>ACL</acronym>, any descendant page will also
  264. be excluded from rendering.
  265. </para>
  266. <para>
  267. The
  268. <link linkend="zend.view.helpers.initial.navigation.navigation">proxy
  269. helper</link> will inject its own <acronym>ACL</acronym> and role to the helper it
  270. proxies to if the proxied helper doesn't already have any.
  271. </para>
  272. <para>
  273. The examples below all show how <acronym>ACL</acronym> affects rendering.
  274. </para>
  275. </sect4>
  276. <sect4 id="zend.view.helpers.initial.navigation.setup">
  277. <title>Navigation setup used in examples</title>
  278. <para>
  279. This example shows the setup of a navigation container for a
  280. fictional software company.
  281. </para>
  282. <para>
  283. Notes on the setup:
  284. </para>
  285. <itemizedlist>
  286. <listitem>
  287. <para>
  288. The domain for the site is <code>www.example.com</code>.
  289. </para>
  290. </listitem>
  291. <listitem>
  292. <para>
  293. Interesting page properties are marked with a comment.
  294. </para>
  295. </listitem>
  296. <listitem>
  297. <para>
  298. Unless otherwise is stated in other examples, the user
  299. is requesting the <acronym>URL</acronym>
  300. <code>http://www.example.com/products/server/faq/</code>,
  301. which translates to the page labeled <constant>FAQ</constant>
  302. under <code>Foo Server</code>.
  303. </para>
  304. </listitem>
  305. <listitem>
  306. <para>
  307. The assumed <acronym>ACL</acronym> and router setup is shown below the
  308. container setup.
  309. </para>
  310. </listitem>
  311. </itemizedlist>
  312. <programlisting language="php"><![CDATA[
  313. /*
  314. * Navigation container (config/array)
  315. * Each element in the array will be passed to
  316. * Zend_Navigation_Page::factory() when constructing
  317. * the navigation container below.
  318. */
  319. $pages = array(
  320. array(
  321. 'label' => 'Home',
  322. 'title' => 'Go Home',
  323. 'module' => 'default',
  324. 'controller' => 'index',
  325. 'action' => 'index',
  326. 'order' => -100 // make sure home is the first page
  327. ),
  328. array(
  329. 'label' => 'Special offer this week only!',
  330. 'module' => 'store',
  331. 'controller' => 'offer',
  332. 'action' => 'amazing',
  333. 'visible' => false // not visible
  334. ),
  335. array(
  336. 'label' => 'Products',
  337. 'module' => 'products',
  338. 'controller' => 'index',
  339. 'action' => 'index',
  340. 'pages' => array(
  341. array(
  342. 'label' => 'Foo Server',
  343. 'module' => 'products',
  344. 'controller' => 'server',
  345. 'action' => 'index',
  346. 'pages' => array(
  347. array(
  348. 'label' => 'FAQ',
  349. 'module' => 'products',
  350. 'controller' => 'server',
  351. 'action' => 'faq',
  352. 'rel' => array(
  353. 'canonical' => 'http://www.example.com/?page=faq',
  354. 'alternate' => array(
  355. 'module' => 'products',
  356. 'controller' => 'server',
  357. 'action' => 'faq',
  358. 'params' => array('format' => 'xml')
  359. )
  360. )
  361. ),
  362. array(
  363. 'label' => 'Editions',
  364. 'module' => 'products',
  365. 'controller' => 'server',
  366. 'action' => 'editions'
  367. ),
  368. array(
  369. 'label' => 'System Requirements',
  370. 'module' => 'products',
  371. 'controller' => 'server',
  372. 'action' => 'requirements'
  373. )
  374. )
  375. ),
  376. array(
  377. 'label' => 'Foo Studio',
  378. 'module' => 'products',
  379. 'controller' => 'studio',
  380. 'action' => 'index',
  381. 'pages' => array(
  382. array(
  383. 'label' => 'Customer Stories',
  384. 'module' => 'products',
  385. 'controller' => 'studio',
  386. 'action' => 'customers'
  387. ),
  388. array(
  389. 'label' => 'Support',
  390. 'module' => 'prodcts',
  391. 'controller' => 'studio',
  392. 'action' => 'support'
  393. )
  394. )
  395. )
  396. )
  397. ),
  398. array(
  399. 'label' => 'Company',
  400. 'title' => 'About us',
  401. 'module' => 'company',
  402. 'controller' => 'about',
  403. 'action' => 'index',
  404. 'pages' => array(
  405. array(
  406. 'label' => 'Investor Relations',
  407. 'module' => 'company',
  408. 'controller' => 'about',
  409. 'action' => 'investors'
  410. ),
  411. array(
  412. 'label' => 'News',
  413. 'class' => 'rss', // class
  414. 'module' => 'company',
  415. 'controller' => 'news',
  416. 'action' => 'index',
  417. 'pages' => array(
  418. array(
  419. 'label' => 'Press Releases',
  420. 'module' => 'company',
  421. 'controller' => 'news',
  422. 'action' => 'press'
  423. ),
  424. array(
  425. 'label' => 'Archive',
  426. 'route' => 'archive', // route
  427. 'module' => 'company',
  428. 'controller' => 'news',
  429. 'action' => 'archive'
  430. )
  431. )
  432. )
  433. )
  434. ),
  435. array(
  436. 'label' => 'Community',
  437. 'module' => 'community',
  438. 'controller' => 'index',
  439. 'action' => 'index',
  440. 'pages' => array(
  441. array(
  442. 'label' => 'My Account',
  443. 'module' => 'community',
  444. 'controller' => 'account',
  445. 'action' => 'index',
  446. 'resource' => 'mvc:community.account' // resource
  447. ),
  448. array(
  449. 'label' => 'Forums',
  450. 'uri' => 'http://forums.example.com/',
  451. 'class' => 'external' // class
  452. )
  453. )
  454. ),
  455. array(
  456. 'label' => 'Administration',
  457. 'module' => 'admin',
  458. 'controller' => 'index',
  459. 'action' => 'index',
  460. 'resource' => 'mvc:admin', // resource
  461. 'pages' => array(
  462. array(
  463. 'label' => 'Write new article',
  464. 'module' => 'admin',
  465. 'controller' => 'post',
  466. 'aciton' => 'write'
  467. )
  468. )
  469. )
  470. );
  471. // Create container from array
  472. $container = new Zend_Navigation($pages);
  473. // Store the container in the proxy helper:
  474. $view->getHelper('navigation')->setContainer($container);
  475. // ...or simply:
  476. $view->navigation($container);
  477. // ...or store it in the reigstry:
  478. Zend_Registry::set('Zend_Navigation', $container);
  479. ]]></programlisting>
  480. <para>
  481. In addition to the container above, the following setup is assumed:
  482. </para>
  483. <programlisting language="php"><![CDATA[
  484. // Setup router (default routes and 'archive' route):
  485. $front = Zend_Controller_Front::getInstance();
  486. $router = $front->getRouter();
  487. $router->addDefaultRoutes();
  488. $router->addRoute(
  489. 'archive',
  490. new Zend_Controller_Router_Route(
  491. '/archive/:year',
  492. array(
  493. 'module' => 'company',
  494. 'controller' => 'news',
  495. 'action' => 'archive',
  496. 'year' => (int) date('Y') - 1
  497. ),
  498. array('year' => '\d+')
  499. )
  500. );
  501. // Setup ACL:
  502. $acl = new Zend_Acl();
  503. $acl->addRole(new Zend_Acl_Role('member'));
  504. $acl->addRole(new Zend_Acl_Role('admin'));
  505. $acl->add(new Zend_Acl_Resource('mvc:admin'));
  506. $acl->add(new Zend_Acl_Resource('mvc:community.account'));
  507. $acl->allow('member', 'mvc:community.account');
  508. $acl->allow('admin', null);
  509. // Store ACL and role in the proxy helper:
  510. $view->navigation()->setAcl($acl)->setRole('member');
  511. // ...or set default ACL and role statically:
  512. Zend_View_Helper_Navigation_HelperAbstract::setDefaultAcl($acl);
  513. Zend_View_Helper_Navigation_HelperAbstract::setDefaultRole('member');
  514. ]]></programlisting>
  515. </sect4>
  516. <sect4 id="zend.view.helpers.initial.navigation.breadcrumbs">
  517. <title>Breadcrumbs Helper</title>
  518. <para>
  519. Breadcrumbs are used for indicating where in a sitemap
  520. a user is currently browsing, and are typically rendered
  521. like this: "You are here: Home > Products > FantasticProduct 1.0".
  522. The breadcrumbs helper follows the guidelines from <ulink
  523. url="http://developer.yahoo.com/ypatterns/pattern.php?pattern=breadcrumbs">Breadcrumbs
  524. Pattern - Yahoo! Design Pattern Library</ulink>,
  525. and allows simple customization (minimum/maximum depth, indentation,
  526. separator, and whether the last element should be linked), or
  527. rendering using a partial view script.
  528. </para>
  529. <para>
  530. The Breadcrumbs helper works like this; it finds the deepest active
  531. page in a navigation container, and renders an upwards path to
  532. the root. For <acronym>MVC</acronym> pages, the "activeness" of a page is
  533. determined by inspecting the request object, as stated in the
  534. section on <link linkend="zend.navigation.pages.mvc">Zend_Navigation_Page_Mvc</link>.
  535. </para>
  536. <para>
  537. The helper sets the <code>minDepth</code> property to 1 by default,
  538. meaning breadcrumbs will not be rendered if the deepest active page
  539. is a root page. If <code>maxDepth</code> is specified, the helper
  540. will stop rendering when at the specified depth (e.g. stop at level
  541. 2 even if the deepest active page is on level 3).
  542. </para>
  543. <para>
  544. Methods in the breadcrumbs helper:
  545. </para>
  546. <itemizedlist>
  547. <listitem>
  548. <para>
  549. <code>{get|set}Separator()</code> gets/sets separator
  550. string that is used between breadcrumbs. Defualt is
  551. <code>' &amp;gt; '</code>.
  552. </para>
  553. </listitem>
  554. <listitem>
  555. <para>
  556. <code>{get|set}LinkLast()</code> gets/sets whether the
  557. last breadcrumb should be rendered as an anchor or not.
  558. Default is <constant>FALSE</constant>.
  559. </para>
  560. </listitem>
  561. <listitem>
  562. <para>
  563. <code>{get|set}Partial()</code> gets/sets a partial view
  564. script that should be used for rendering breadcrumbs.
  565. If a partial view script is set, the helper's
  566. <methodname>render()</methodname> method will use the
  567. <methodname>renderPartial()</methodname> method. If no partial is
  568. set, the <methodname>renderStraight()</methodname> method is used.
  569. The helper expects the partial to be a <type>String</type>
  570. or an <type>Array</type> with two elements. If the partial
  571. is a <type>String</type>, it denotes the name of the partial
  572. script to use. If it is an <type>Array</type>, the first
  573. element will be used as the name of the partial view
  574. script, and the second element is the module where the
  575. script is found.
  576. </para>
  577. </listitem>
  578. <listitem>
  579. <para>
  580. <methodname>renderStraight()</methodname> is the default render
  581. method.
  582. </para>
  583. </listitem>
  584. <listitem>
  585. <para>
  586. <methodname>renderPartial()</methodname> is used for rendering
  587. using a partial view script.
  588. </para>
  589. </listitem>
  590. </itemizedlist>
  591. <example id="zend.view.helpers.initial.navigation.breadcrumbs.example1">
  592. <title>Rendering breadcrumbs</title>
  593. <para>
  594. This example shows how to render breadcrumbs with default
  595. settings.
  596. </para>
  597. <programlisting language="php"><![CDATA[
  598. In a view script or layout:
  599. <?php echo $this->navigation()->breadcrumbs(); ?>
  600. The two calls above take advantage of the magic __toString() method,
  601. and are equivalent to:
  602. <?php echo $this->navigation()->breadcrumbs()->render(); ?>
  603. Output:
  604. <a href="/products">Products</a> &gt; <a href="/products/server">Foo Server</a> &gt; FAQ
  605. ]]></programlisting>
  606. </example>
  607. <example id="zend.view.helpers.initial.navigation.breadcrumbs.example2">
  608. <title>Specifying indentation</title>
  609. <para>
  610. This example shows how to render breadcrumbs with initial
  611. indentation.
  612. </para>
  613. <programlisting language="php"><![CDATA[
  614. Rendering with 8 spaces indentation:
  615. <?php echo $this->navigation()->breadcrumbs()->setIndent(8);?>
  616. Output:
  617. <a href="/products">Products</a> &gt; <a href="/products/server">Foo Server</a> &gt; FAQ
  618. ]]></programlisting>
  619. </example>
  620. <example id="zend.view.helpers.initial.navigation.breadcrumbs.example3">
  621. <title>Customize breadcrumbs output</title>
  622. <para>
  623. This example shows how to customze breadcrumbs output by
  624. specifying various options.
  625. </para>
  626. <programlisting language="php"><![CDATA[
  627. In a view script or layout:
  628. <?php
  629. echo $this->navigation()
  630. ->breadcrumbs()
  631. ->setLinkLast(true) // link last page
  632. ->setMaxDepth(1) // stop at level 1
  633. ->setSeparator(' &#9654;' . PHP_EOL); // cool separator with newline
  634. ?>
  635. Output:
  636. <a href="/products">Products</a> &#9654;
  637. <a href="/products/server">Foo Server</a>
  638. /////////////////////////////////////////////////////
  639. Setting minimum depth required to render breadcrumbs:
  640. <?php
  641. $this->navigation()->breadcrumbs()->setMinDepth(10);
  642. echo $this->navigation()->breadcrumbs();
  643. ?>
  644. Output:
  645. Nothing, because the deepest active page is not at level 10 or deeper.
  646. ]]></programlisting>
  647. </example>
  648. <example id="zend.view.helpers.initial.navigation.breadcrumbs.example4">
  649. <title>Rendering breadcrumbs using a partial view script</title>
  650. <para>
  651. This example shows how to render customized breadcrumbs using
  652. a partial vew script. By calling <methodname>setPartial()</methodname>,
  653. you can specify a partial view script that will be used
  654. when calling <methodname>render()</methodname>. When a partial is specified,
  655. the <methodname>renderPartial()</methodname> method will be called. This
  656. method will find the deepest active page and pass an array
  657. of pages that leads to the active page to the partial view
  658. script.
  659. </para>
  660. <para>
  661. In a layout:
  662. </para>
  663. <programlisting language="php"><![CDATA[
  664. $partial = ;
  665. echo $this->navigation()->breadcrumbs()
  666. ->setPartial(array('breadcrumbs.phtml', 'default'));
  667. ]]></programlisting>
  668. <para>
  669. Contents of
  670. <code>application/modules/default/views/breadcrumbs.phtml</code>:
  671. </para>
  672. <programlisting language="php"><![CDATA[
  673. echo implode(', ', array_map(
  674. function ($a) { return $a->getLabel(); },
  675. $this->pages));
  676. ]]></programlisting>
  677. <para>
  678. Output:
  679. </para>
  680. <programlisting language="php"><![CDATA[
  681. Products, Foo Server, FAQ
  682. ]]></programlisting>
  683. </example>
  684. </sect4>
  685. <sect4 id="zend.view.helpers.initial.navigation.links">
  686. <title>Links Helper</title>
  687. <para>
  688. The links helper is used for rendering <acronym>HTML</acronym> <constant>LINK</constant>
  689. elements. Links are used for describing document relationships
  690. of the currently active page. Read more about links and link
  691. types at <ulink url="http://www.w3.org/TR/html4/struct/links.html#h-12.3">Document
  692. relationships: the LINK element (HTML4 W3C Rec.)</ulink>
  693. and <ulink
  694. url="http://www.w3.org/TR/html4/types.html#h-6.12">Link types (HTML4 W3C
  695. Rec.)</ulink> in the <acronym>HTML</acronym>4 W3C Recommendation.
  696. </para>
  697. <para>
  698. There are two types of relations; forward and reverse, indicated
  699. by the keyords <code>'rel'</code> and <code>'rev'</code>. Most
  700. methods in the helper will take a <varname>$rel</varname> param, which
  701. must be either <code>'rel'</code> or <code>'rev'</code>. Most
  702. methods also take a <varname>$type</varname> param, which is used
  703. for specifying the link type (e.g. alternate, start, next, prev,
  704. chapter, etc).
  705. </para>
  706. <para>
  707. Relationships can be added to page objects manually, or found
  708. by traversing the container registered in the helper. The method
  709. <methodname>findRelation($page, $rel, $type)</methodname> will first try
  710. to find the given <varname>$rel</varname> of <varname>$type</varname> from
  711. the <varname>$page</varname> by calling <code>$page->findRel($type)</code>
  712. or <code>$page->findRel($type)</code>. If the <varname>$page</varname>
  713. has a relation that can be converted to a page instance, that
  714. relation will be used. If the <varname>$page</varname> instance doesn't
  715. have the specified <varname>$type</varname>, the helper will look for
  716. a method in the helper named <code>search$rel$type</code> (e.g.
  717. <methodname>searchRelNext()</methodname> or
  718. <methodname>searchRevAlternate()</methodname>).
  719. If such a method exists, it will be used for determining the
  720. <varname>$page</varname>'s relation by traversing the container.
  721. </para>
  722. <para>
  723. Not all relations can be determined by traversing the container.
  724. These are the relations that will be found by searching:
  725. </para>
  726. <itemizedlist>
  727. <listitem>
  728. <para>
  729. <methodname>searchRelStart()</methodname>, forward 'start'
  730. relation: the first page in the container.
  731. </para>
  732. </listitem>
  733. <listitem>
  734. <para>
  735. <methodname>searchRelNext()</methodname>, forward 'next'
  736. relation; finds the next page in the container, i.e.
  737. the page after the active page.
  738. </para>
  739. </listitem>
  740. <listitem>
  741. <para>
  742. <methodname>searchRelPrev()</methodname>, forward 'prev'
  743. relation; finds the previous page, i.e. the page before
  744. the active page.
  745. </para>
  746. </listitem>
  747. <listitem>
  748. <para>
  749. <methodname>searchRelChapter()</methodname>, forward 'chapter'
  750. relations; finds all pages on level 0 except the 'start'
  751. relation or the active page if it's on level 0.
  752. </para>
  753. </listitem>
  754. <listitem>
  755. <para>
  756. <methodname>searchRelSection()</methodname>, forward 'section'
  757. relations; finds all child pages of the active page if
  758. the active page is on level 0 (a 'chapter').
  759. </para>
  760. </listitem>
  761. <listitem>
  762. <para>
  763. <methodname>searchRelSubsection()</methodname>, forward 'subsection'
  764. relations; finds all child pages of the active page if
  765. the active pages is on level 1 (a 'section').
  766. </para>
  767. </listitem>
  768. <listitem>
  769. <para>
  770. <methodname>searchRevSection()</methodname>, reverse 'section'
  771. relation; finds the parent of the active page if the
  772. active page is on level 1 (a 'section').
  773. </para>
  774. </listitem>
  775. <listitem>
  776. <para>
  777. <methodname>searchRevSubsection()</methodname>, reverse 'subsection'
  778. relation; finds the parent of the active page if the
  779. active page is on level 2 (a 'subsection').
  780. </para>
  781. </listitem>
  782. </itemizedlist>
  783. <note>
  784. <para>
  785. When looking for relations in the page instance
  786. (<code>$page->getRel($type)</code> or
  787. <code>$page->getRev($type)</code>), the helper accepts the
  788. values of type <type>String</type>, <type>Array</type>,
  789. <classname>Zend_Config</classname>, or
  790. <classname>Zend_Navigation_Page</classname>. If a string
  791. is found, it will be converted to a
  792. <classname>Zend_Navigation_Page_Uri</classname>. If an array
  793. or a config is found, it will be converted to one or several
  794. page instances. If the first key of the array/config is numeric,
  795. it will be considered to contain several pages, and each
  796. element will be passed to the
  797. <link linkend="zend.navigation.pages.factory">page factory</link>.
  798. If the first key is not numeric, the array/config will be
  799. passed to the page factory directly, and a single page will
  800. be returned.
  801. </para>
  802. </note>
  803. <para>
  804. The helper also supports magic methods for finding relations.
  805. E.g. to find forward alternate relations, call
  806. <code>$helper->findRelAlternate($page)</code>, and to find
  807. reverse section relations, call
  808. <code>$helper->findRevSection($page)</code>. Those calls correspond
  809. to <code>$helper->findRelation($page, 'rel', 'alternate');</code>
  810. and <code>$helper->findRelation($page, 'rev', 'section');</code>
  811. respectively.
  812. </para>
  813. <para>
  814. To customize which relations should be rendered, the helper
  815. uses a render flag. The render flag is an integer value, and will be
  816. used in a
  817. <ulink url="http://php.net/manual/en/language.operators.bitwise.php">bitwse
  818. <code>and</code> (<code>&amp;</code>) operation</ulink> against the
  819. helper's render constants to determine if the relation that belongs
  820. to the render constant should be rendered.
  821. </para>
  822. <para>
  823. See the
  824. <link linkend="zend.view.helpers.initial.navigation.links.example3">example
  825. below</link> for more information.
  826. </para>
  827. <itemizedlist>
  828. <listitem>
  829. <para>
  830. <constant>Zend_View_Helper_Navigation_Links::RENDER_ALTERNATE</constant>
  831. </para>
  832. </listitem>
  833. <listitem>
  834. <para>
  835. <constant>Zend_View_Helper_Navigation_Links::RENDER_STYLESHEET</constant>
  836. </para>
  837. </listitem>
  838. <listitem>
  839. <para>
  840. <constant>Zend_View_Helper_Navigation_Links::RENDER_START</constant>
  841. </para>
  842. </listitem>
  843. <listitem>
  844. <para>
  845. <constant>Zend_View_Helper_Navigation_Links::RENDER_NEXT</constant>
  846. </para>
  847. </listitem>
  848. <listitem>
  849. <para>
  850. <constant>Zend_View_Helper_Navigation_Links::RENDER_PREV</constant>
  851. </para>
  852. </listitem>
  853. <listitem>
  854. <para>
  855. <constant>Zend_View_Helper_Navigation_Links::RENDER_CONTENTS</constant>
  856. </para>
  857. </listitem>
  858. <listitem>
  859. <para>
  860. <constant>Zend_View_Helper_Navigation_Links::RENDER_INDEX</constant>
  861. </para>
  862. </listitem>
  863. <listitem>
  864. <para>
  865. <constant>Zend_View_Helper_Navigation_Links::RENDER_GLOSSARY</constant>
  866. </para>
  867. </listitem>
  868. <listitem>
  869. <para>
  870. <constant>Zend_View_Helper_Navigation_Links::RENDER_COPYRIGHT</constant>
  871. </para>
  872. </listitem>
  873. <listitem>
  874. <para>
  875. <constant>Zend_View_Helper_Navigation_Links::RENDER_CHAPTER</constant>
  876. </para>
  877. </listitem>
  878. <listitem>
  879. <para>
  880. <constant>Zend_View_Helper_Navigation_Links::RENDER_SECTION</constant>
  881. </para>
  882. </listitem>
  883. <listitem>
  884. <para>
  885. <constant>Zend_View_Helper_Navigation_Links::RENDER_SUBSECTION</constant>
  886. </para>
  887. </listitem>
  888. <listitem>
  889. <para>
  890. <constant>Zend_View_Helper_Navigation_Links::RENDER_APPENDIX</constant>
  891. </para>
  892. </listitem>
  893. <listitem>
  894. <para>
  895. <constant>Zend_View_Helper_Navigation_Links::RENDER_HELP</constant>
  896. </para>
  897. </listitem>
  898. <listitem>
  899. <para>
  900. <constant>Zend_View_Helper_Navigation_Links::RENDER_BOOKMARK</constant>
  901. </para>
  902. </listitem>
  903. <listitem>
  904. <para>
  905. <constant>Zend_View_Helper_Navigation_Links::RENDER_CUSTOM</constant>
  906. </para>
  907. </listitem>
  908. <listitem>
  909. <para>
  910. <constant>Zend_View_Helper_Navigation_Links::RENDER_ALL</constant>
  911. </para>
  912. </listitem>
  913. </itemizedlist>
  914. <para>
  915. The constants from <constant>RENDER_ALTERNATE</constant> to
  916. <constant>RENDER_BOOKMARK</constant> denote standard <acronym>HTML</acronym> link types.
  917. <constant>RENDER_CUSTOM</constant> denotes non-standard relations that
  918. specified in pages. <constant>RENDER_ALL</constant> denotes standard and
  919. non-standard relations.
  920. </para>
  921. <para>
  922. Methods in the links helper:
  923. </para>
  924. <itemizedlist>
  925. <listitem>
  926. <para>
  927. <code>{get|set}RenderFlag()</code> gets/sets the render
  928. flag. Default is <constant>RENDER_ALL</constant>. See examples
  929. below on how to set the render flag.
  930. </para>
  931. </listitem>
  932. <listitem>
  933. <para>
  934. <methodname>findAllRelations()</methodname> finds all relations of
  935. all types for a given page.
  936. </para>
  937. </listitem>
  938. <listitem>
  939. <para>
  940. <methodname>findRelation()</methodname> finds all relations of a given
  941. type from a given page.
  942. </para>
  943. </listitem>
  944. <listitem>
  945. <para>
  946. <code>searchRel{Start|Next|Prev|Chapter|Section|Subsection}()</code>
  947. traverses a container to find forward relations to
  948. the start page, the next page, the previous page,
  949. chapters, sections, and subsections.
  950. </para>
  951. </listitem>
  952. <listitem>
  953. <para>
  954. <code>searchRev{Section|Subsection}()</code> traverses
  955. a container to find reverse relations to sections or
  956. subsections.
  957. </para>
  958. </listitem>
  959. <listitem>
  960. <para>
  961. <methodname>renderLink()</methodname> renders a single <code>link</code>
  962. element.
  963. </para>
  964. </listitem>
  965. </itemizedlist>
  966. <example id="zend.view.helpers.initial.navigation.links.example1">
  967. <title>Specify relations in pages</title>
  968. <para>
  969. This example shows how to specify relations in pages.
  970. </para>
  971. <programlisting language="php"><![CDATA[
  972. $container = new Zend_Navigation(array(
  973. array(
  974. 'label' => 'Relations using strings',
  975. 'rel' => array(
  976. 'alternate' => 'http://www.example.org/'
  977. ),
  978. 'rev' => array(
  979. 'alternate' => 'http://www.example.net/'
  980. )
  981. ),
  982. array(
  983. 'label' => 'Relations using arrays',
  984. 'rel' => array(
  985. 'alternate' => array(
  986. 'label' => 'Example.org',
  987. 'uri' => 'http://www.example.org/'
  988. )
  989. )
  990. ),
  991. array(
  992. 'label' => 'Relations using configs',
  993. 'rel' => array(
  994. 'alternate' => new Zend_Config(array(
  995. 'label' => 'Example.org',
  996. 'uri' => 'http://www.example.org/'
  997. ))
  998. )
  999. ),
  1000. array(
  1001. 'label' => 'Relations using pages instance',
  1002. 'rel' => array(
  1003. 'alternate' => Zend_Navigation_Page::factory(array(
  1004. 'label' => 'Example.org',
  1005. 'uri' => 'http://www.example.org/'
  1006. ))
  1007. )
  1008. )
  1009. ));
  1010. ]]></programlisting>
  1011. </example>
  1012. <example id="zend.view.helpers.initial.navigation.links.example2">
  1013. <title>Default rendering of links</title>
  1014. <para>
  1015. This example shows how to render a menu from a container
  1016. registered/found in the view helper.
  1017. </para>
  1018. <programlisting language="php"><![CDATA[
  1019. In a view script or layout:
  1020. <?php echo $this->view->navigation()->links(); ?>
  1021. Output:
  1022. <link rel="alternate" href="/products/server/faq/format/xml">
  1023. <link rel="start" href="/" title="Home">
  1024. <link rel="next" href="/products/server/editions" title="Editions">
  1025. <link rel="prev" href="/products/server" title="Foo Server">
  1026. <link rel="chapter" href="/products" title="Products">
  1027. <link rel="chapter" href="/company/about" title="Company">
  1028. <link rel="chapter" href="/community" title="Community">
  1029. <link rel="canonical" href="http://www.example.com/?page=server-faq">
  1030. <link rev="subsection" href="/products/server" title="Foo Server">
  1031. ]]></programlisting>
  1032. </example>
  1033. <example id="zend.view.helpers.initial.navigation.links.example3">
  1034. <title>Specify which relations to render</title>
  1035. <para>
  1036. This example shows how to specify which relations to find
  1037. and render.
  1038. </para>
  1039. <programlisting language="php"><![CDATA[
  1040. Render only start, next, and prev:
  1041. $helper->setRenderFlag(Zend_View_Helper_Navigation_Links::RENDER_START |
  1042. Zend_View_Helper_Navigation_Links::RENDER_NEXT |
  1043. Zend_View_Helper_Navigation_Links::RENDER_PREV);
  1044. Output:
  1045. <link rel="start" href="/" title="Home">
  1046. <link rel="next" href="/products/server/editions" title="Editions">
  1047. <link rel="prev" href="/products/server" title="Foo Server">
  1048. ]]></programlisting>
  1049. <programlisting language="php"><![CDATA[
  1050. Render only native link types:
  1051. $helper->setRenderFlag(Zend_View_Helper_Navigation_Links::RENDER_ALL ^
  1052. Zend_View_Helper_Navigation_Links::RENDER_CUSTOM);
  1053. Output:
  1054. <link rel="alternate" href="/products/server/faq/format/xml">
  1055. <link rel="start" href="/" title="Home">
  1056. <link rel="next" href="/products/server/editions" title="Editions">
  1057. <link rel="prev" href="/products/server" title="Foo Server">
  1058. <link rel="chapter" href="/products" title="Products">
  1059. <link rel="chapter" href="/company/about" title="Company">
  1060. <link rel="chapter" href="/community" title="Community">
  1061. <link rev="subsection" href="/products/server" title="Foo Server">
  1062. ]]></programlisting>
  1063. <programlisting language="php"><![CDATA[
  1064. Render all but chapter:
  1065. $helper->setRenderFlag(Zend_View_Helper_Navigation_Links::RENDER_ALL ^
  1066. Zend_View_Helper_Navigation_Links::RENDER_CHAPTER);
  1067. Output:
  1068. <link rel="alternate" href="/products/server/faq/format/xml">
  1069. <link rel="start" href="/" title="Home">
  1070. <link rel="next" href="/products/server/editions" title="Editions">
  1071. <link rel="prev" href="/products/server" title="Foo Server">
  1072. <link rel="canonical" href="http://www.example.com/?page=server-faq">
  1073. <link rev="subsection" href="/products/server" title="Foo Server">
  1074. ]]></programlisting>
  1075. </example>
  1076. </sect4>
  1077. <sect4 id="zend.view.helpers.initial.navigation.menu">
  1078. <title>Menu Helper</title>
  1079. <para>
  1080. The Menu helper is used for rendering menus from navigation
  1081. containers. By default, the menu will be rendered using
  1082. <acronym>HTML</acronym> <code>UL</code> and <code>LI</code> tags, but the helper also
  1083. allows using a partial view script.
  1084. </para>
  1085. <para>
  1086. Methods in the Menu helper:
  1087. </para>
  1088. <itemizedlist>
  1089. <listitem>
  1090. <para>
  1091. <code>{get|set}UlClass()</code> gets/sets the <acronym>CSS</acronym> class
  1092. used in <methodname>renderMenu()</methodname>.
  1093. </para>
  1094. </listitem>
  1095. <listitem>
  1096. <para>
  1097. <code>{get|set}ActiveClass()</code> gets/sets the <acronym>CSS</acronym> class
  1098. for the active elements when rendering.
  1099. </para>
  1100. </listitem>
  1101. <listitem>
  1102. <para>
  1103. <code>{get|set}OnlyActiveBranch()</code> gets/sets a flag
  1104. specifying whether only the active branch of a container
  1105. should be rendered.
  1106. </para>
  1107. </listitem>
  1108. <listitem>
  1109. <para>
  1110. <code>{get|set}ExpandSiblingNodesOfActiveBranch()</code>
  1111. gets/sets a flag specifying whether the sibling nodes of all
  1112. nodes in the active branch should also be expanded and rendered.
  1113. </para>
  1114. </listitem>
  1115. <listitem>
  1116. <para>
  1117. <code>{get|set}RenderParents()</code> gets/sets a flag
  1118. specifying whether parents should be rendered when only
  1119. rendering active branch of a container. If set to
  1120. <constant>FALSE</constant>, only the deepest active menu will be
  1121. rendered.
  1122. </para>
  1123. </listitem>
  1124. <listitem>
  1125. <para>
  1126. <code>{get|set}Partial()</code> gets/sets a partial view
  1127. script that should be used for rendering menu.
  1128. If a partial view script is set, the helper's
  1129. <methodname>render()</methodname> method will use the
  1130. <methodname>renderPartial()</methodname> method. If no partial is
  1131. set, the <methodname>renderMenu()</methodname> method is used.
  1132. The helper expects the partial to be a <type>String</type>
  1133. or an <type>Array</type> with two elements. If the partial
  1134. is a <type>String</type>, it denotes the name of the partial
  1135. script to use. If it is an <type>Array</type>, the first
  1136. element will be used as the name of the partial view
  1137. script, and the second element is the module where the
  1138. script is found.
  1139. </para>
  1140. </listitem>
  1141. <listitem>
  1142. <para>
  1143. <methodname>htmlify()</methodname> overrides the method from the
  1144. abstract class to return <code>span</code> elements
  1145. if the page has no <code>href</code>.
  1146. </para>
  1147. </listitem>
  1148. <listitem>
  1149. <para>
  1150. <methodname>renderMenu($container = null, $options = array())</methodname>
  1151. is the default render method, and will render a container as
  1152. a <acronym>HTML</acronym> <code>UL</code> list.
  1153. </para>
  1154. <para>
  1155. If <varname>$container</varname> is not given, the container
  1156. registered in the helper will be rendered.
  1157. </para>
  1158. <para>
  1159. <varname>$options</varname> is used for overriding options
  1160. specified temporarily without rsetting the values in the
  1161. helper instance. It is an associative array where each key
  1162. corresponds to an option in the helper.
  1163. </para>
  1164. <para>
  1165. Recognized options:
  1166. </para>
  1167. <itemizedlist>
  1168. <listitem>
  1169. <para>
  1170. <code>indent</code>; indentation. Expects a
  1171. <type>String</type> or an <code>int</code>
  1172. value.
  1173. </para>
  1174. </listitem>
  1175. <listitem>
  1176. <para>
  1177. <code>minDepth</code>; minimum depth. Expcects
  1178. an <code>int</code> or <constant>NULL</constant> (no
  1179. minimum depth).
  1180. </para>
  1181. </listitem>
  1182. <listitem>
  1183. <para>
  1184. <code>maxDepth</code>; maximum depth. Expcects
  1185. an <code>int</code> or <constant>NULL</constant> (no
  1186. maximum depth).
  1187. </para>
  1188. </listitem>
  1189. <listitem>
  1190. <para>
  1191. <code>ulClass</code>; <acronym>CSS</acronym> class for
  1192. <code>ul</code> element. Expects a
  1193. <type>String</type>.
  1194. </para>
  1195. </listitem>
  1196. <listitem>
  1197. <para>
  1198. <code>activeClass</code>; <acronym>CSS</acronym> class for
  1199. for the active elements when rendering. Expects a
  1200. <type>String</type>.
  1201. </para>
  1202. </listitem>
  1203. <listitem>
  1204. <para>
  1205. <code>onlyActiveBranch</code>; whether only
  1206. active branch should be rendered. Expects
  1207. a <type>Boolean</type> value.
  1208. </para>
  1209. </listitem>
  1210. <listitem>
  1211. <para>
  1212. <code>expandSiblingNodesOfActiveBranch</code>;
  1213. whether the sibling nodes of nodes in the active
  1214. branch should be expanded and rendered. Expects
  1215. a <type>Boolean</type> value.
  1216. </para>
  1217. </listitem>
  1218. <listitem>
  1219. <para>
  1220. <code>renderParents</code>; whether parents
  1221. should be rendered if only rendering active
  1222. branch. Expects a <type>Boolean</type> value.
  1223. </para>
  1224. </listitem>
  1225. </itemizedlist>
  1226. <para>
  1227. If an option is not given, the value set in the helper
  1228. will be used.
  1229. </para>
  1230. </listitem>
  1231. <listitem>
  1232. <para>
  1233. <methodname>renderPartial()</methodname> is used for rendering the menu
  1234. using a partial view script.
  1235. </para>
  1236. </listitem>
  1237. <listitem>
  1238. <para>
  1239. <methodname>renderSubMenu()</methodname> renders the deepest menu level
  1240. of a container's active branch.
  1241. </para>
  1242. </listitem>
  1243. </itemizedlist>
  1244. <example id="zend.view.helpers.initial.navigation.menu.example1">
  1245. <title>Rendering a menu</title>
  1246. <para>
  1247. This example shows how to render a menu from a container
  1248. registered/found in the view helper. Notice how pages
  1249. are filtered out based on visibility and <acronym>ACL</acronym>.
  1250. </para>
  1251. <programlisting language="php"><![CDATA[
  1252. In a view script or layout:
  1253. <?php echo $this->navigation()->menu()->render() ?>
  1254. Or simply:
  1255. <?php echo $this->navigation()->menu() ?>
  1256. Output:
  1257. <ul class="navigation">
  1258. <li>
  1259. <a title="Go Home" href="/">Home</a>
  1260. </li>
  1261. <li class="active">
  1262. <a href="/products">Products</a>
  1263. <ul>
  1264. <li class="active">
  1265. <a href="/products/server">Foo Server</a>
  1266. <ul>
  1267. <li class="active">
  1268. <a href="/products/server/faq">FAQ</a>
  1269. </li>
  1270. <li>
  1271. <a href="/products/server/editions">Editions</a>
  1272. </li>
  1273. <li>
  1274. <a href="/products/server/requirements">System Requirements</a>
  1275. </li>
  1276. </ul>
  1277. </li>
  1278. <li>
  1279. <a href="/products/studio">Foo Studio</a>
  1280. <ul>
  1281. <li>
  1282. <a href="/products/studio/customers">Customer Stories</a>
  1283. </li>
  1284. <li>
  1285. <a href="/prodcts/studio/support">Support</a>
  1286. </li>
  1287. </ul>
  1288. </li>
  1289. </ul>
  1290. </li>
  1291. <li>
  1292. <a title="About us" href="/company/about">Company</a>
  1293. <ul>
  1294. <li>
  1295. <a href="/company/about/investors">Investor Relations</a>
  1296. </li>
  1297. <li>
  1298. <a class="rss" href="/company/news">News</a>
  1299. <ul>
  1300. <li>
  1301. <a href="/company/news/press">Press Releases</a>
  1302. </li>
  1303. <li>
  1304. <a href="/archive">Archive</a>
  1305. </li>
  1306. </ul>
  1307. </li>
  1308. </ul>
  1309. </li>
  1310. <li>
  1311. <a href="/community">Community</a>
  1312. <ul>
  1313. <li>
  1314. <a href="/community/account">My Account</a>
  1315. </li>
  1316. <li>
  1317. <a class="external" href="http://forums.example.com/">Forums</a>
  1318. </li>
  1319. </ul>
  1320. </li>
  1321. </ul>
  1322. ]]></programlisting>
  1323. </example>
  1324. <example id="zend.view.helpers.initial.navigation.menu.example2">
  1325. <title>Calling renderMenu() directly</title>
  1326. <para>
  1327. This example shows how to render a menu that is not
  1328. registered in the view helper by calling the
  1329. <methodname>renderMenu()</methodname> directly and specifying a few
  1330. options.
  1331. </para>
  1332. <programlisting language="php"><![CDATA[
  1333. <?php
  1334. // render only the 'Community' menu
  1335. $community = $this->navigation()->findOneByLabel('Community');
  1336. $options = array(
  1337. 'indent' => 16,
  1338. 'ulClass' => 'community'
  1339. );
  1340. echo $this->navigation()
  1341. ->menu()
  1342. ->renderMenu($community, $options);
  1343. ?>
  1344. Output:
  1345. <ul class="community">
  1346. <li>
  1347. <a href="/community/account">My Account</a>
  1348. </li>
  1349. <li>
  1350. <a class="external" href="http://forums.example.com/">Forums</a>
  1351. </li>
  1352. </ul>
  1353. ]]></programlisting>
  1354. </example>
  1355. <example id="zend.view.helpers.initial.navigation.menu.example3">
  1356. <title>Rendering the deepest active menu</title>
  1357. <para>
  1358. This example shows how the <methodname>renderSubMenu()</methodname>
  1359. will render the deepest sub menu of the active branch.
  1360. </para>
  1361. <para>
  1362. Calling <methodname>renderSubMenu($container, $ulClass, $indent)</methodname>
  1363. is equivalent to calling <methodname>renderMenu($container, $options)</methodname>
  1364. with the following options:
  1365. </para>
  1366. <programlisting language="php"><![CDATA[
  1367. array(
  1368. 'ulClass' => $ulClass,
  1369. 'indent' => $indent,
  1370. 'minDepth' => null,
  1371. 'maxDepth' => null,
  1372. 'onlyActiveBranch' => true,
  1373. 'renderParents' => false
  1374. );
  1375. ]]></programlisting>
  1376. <programlisting language="php"><![CDATA[
  1377. <?php
  1378. echo $this->navigation()
  1379. ->menu()
  1380. ->renderSubMenu(null, 'sidebar', 4);
  1381. ?>
  1382. The output will be the same if 'FAQ' or 'Foo Server' is active:
  1383. <ul class="sidebar">
  1384. <li class="active">
  1385. <a href="/products/server/faq">FAQ</a>
  1386. </li>
  1387. <li>
  1388. <a href="/products/server/editions">Editions</a>
  1389. </li>
  1390. <li>
  1391. <a href="/products/server/requirements">System Requirements</a>
  1392. </li>
  1393. </ul>
  1394. ]]></programlisting>
  1395. </example>
  1396. <example id="zend.view.helpers.initial.navigation.menu.example4">
  1397. <title>Rendering a menu with maximum depth</title>
  1398. <programlisting language="php"><![CDATA[
  1399. <?php
  1400. echo $this->navigation()
  1401. ->menu()
  1402. ->setMaxDepth(1);
  1403. ?>
  1404. Output:
  1405. <ul class="navigation">
  1406. <li>
  1407. <a title="Go Home" href="/">Home</a>
  1408. </li>
  1409. <li class="active">
  1410. <a href="/products">Products</a>
  1411. <ul>
  1412. <li class="active">
  1413. <a href="/products/server">Foo Server</a>
  1414. </li>
  1415. <li>
  1416. <a href="/products/studio">Foo Studio</a>
  1417. </li>
  1418. </ul>
  1419. </li>
  1420. <li>
  1421. <a title="About us" href="/company/about">Company</a>
  1422. <ul>
  1423. <li>
  1424. <a href="/company/about/investors">Investor Relations</a>
  1425. </li>
  1426. <li>
  1427. <a class="rss" href="/company/news">News</a>
  1428. </li>
  1429. </ul>
  1430. </li>
  1431. <li>
  1432. <a href="/community">Community</a>
  1433. <ul>
  1434. <li>
  1435. <a href="/community/account">My Account</a>
  1436. </li>
  1437. <li>
  1438. <a class="external" href="http://forums.example.com/">Forums</a>
  1439. </li>
  1440. </ul>
  1441. </li>
  1442. </ul>
  1443. ]]></programlisting>
  1444. </example>
  1445. <example id="zend.view.helpers.initial.navigation.menu.example5">
  1446. <title>Rendering a menu with minimum depth</title>
  1447. <programlisting language="php"><![CDATA[
  1448. <?php
  1449. echo $this->navigation()
  1450. ->menu()
  1451. ->setMinDepth(1);
  1452. ?>
  1453. Output:
  1454. <ul class="navigation">
  1455. <li class="active">
  1456. <a href="/products/server">Foo Server</a>
  1457. <ul>
  1458. <li class="active">
  1459. <a href="/products/server/faq">FAQ</a>
  1460. </li>
  1461. <li>
  1462. <a href="/products/server/editions">Editions</a>
  1463. </li>
  1464. <li>
  1465. <a href="/products/server/requirements">System Requirements</a>
  1466. </li>
  1467. </ul>
  1468. </li>
  1469. <li>
  1470. <a href="/products/studio">Foo Studio</a>
  1471. <ul>
  1472. <li>
  1473. <a href="/products/studio/customers">Customer Stories</a>
  1474. </li>
  1475. <li>
  1476. <a href="/prodcts/studio/support">Support</a>
  1477. </li>
  1478. </ul>
  1479. </li>
  1480. <li>
  1481. <a href="/company/about/investors">Investor Relations</a>
  1482. </li>
  1483. <li>
  1484. <a class="rss" href="/company/news">News</a>
  1485. <ul>
  1486. <li>
  1487. <a href="/company/news/press">Press Releases</a>
  1488. </li>
  1489. <li>
  1490. <a href="/archive">Archive</a>
  1491. </li>
  1492. </ul>
  1493. </li>
  1494. <li>
  1495. <a href="/community/account">My Account</a>
  1496. </li>
  1497. <li>
  1498. <a class="external" href="http://forums.example.com/">Forums</a>
  1499. </li>
  1500. </ul>
  1501. ]]></programlisting>
  1502. </example>
  1503. <example id="zend.view.helpers.initial.navigation.menu.example6">
  1504. <title>Rendering only the active branch of a menu</title>
  1505. <programlisting language="php"><![CDATA[
  1506. <?php
  1507. echo $this->navigation()
  1508. ->menu()
  1509. ->setOnlyActiveBranch(true);
  1510. ?>
  1511. Output:
  1512. <ul class="navigation">
  1513. <li class="active">
  1514. <a href="/products">Products</a>
  1515. <ul>
  1516. <li class="active">
  1517. <a href="/products/server">Foo Server</a>
  1518. <ul>
  1519. <li class="active">
  1520. <a href="/products/server/faq">FAQ</a>
  1521. </li>
  1522. <li>
  1523. <a href="/products/server/editions">Editions</a>
  1524. </li>
  1525. <li>
  1526. <a href="/products/server/requirements">System Requirements</a>
  1527. </li>
  1528. </ul>
  1529. </li>
  1530. </ul>
  1531. </li>
  1532. </ul>
  1533. ]]></programlisting>
  1534. </example>
  1535. <example id="zend.view.helpers.initial.navigation.menu.example7">
  1536. <title>
  1537. Rendering only the active branch of a menu with minimum depth
  1538. </title>
  1539. <programlisting language="php"><![CDATA[
  1540. <?php
  1541. echo $this->navigation()
  1542. ->menu()
  1543. ->setOnlyActiveBranch(true)
  1544. ->setMinDepth(1);
  1545. ?>
  1546. Output:
  1547. <ul class="navigation">
  1548. <li class="active">
  1549. <a href="/products/server">Foo Server</a>
  1550. <ul>
  1551. <li class="active">
  1552. <a href="/products/server/faq">FAQ</a>
  1553. </li>
  1554. <li>
  1555. <a href="/products/server/editions">Editions</a>
  1556. </li>
  1557. <li>
  1558. <a href="/products/server/requirements">System Requirements</a>
  1559. </li>
  1560. </ul>
  1561. </li>
  1562. </ul>
  1563. ]]></programlisting>
  1564. </example>
  1565. <example id="zend.view.helpers.initial.navigation.menu.example8">
  1566. <title>
  1567. Rendering only the active branch of a menu with maximum depth
  1568. </title>
  1569. <programlisting language="php"><![CDATA[
  1570. <?php
  1571. echo $this->navigation()
  1572. ->menu()
  1573. ->setOnlyActiveBranch(true)
  1574. ->setMaxDepth(1);
  1575. ?>
  1576. Output:
  1577. <ul class="navigation">
  1578. <li class="active">
  1579. <a href="/products">Products</a>
  1580. <ul>
  1581. <li class="active">
  1582. <a href="/products/server">Foo Server</a>
  1583. </li>
  1584. <li>
  1585. <a href="/products/studio">Foo Studio</a>
  1586. </li>
  1587. </ul>
  1588. </li>
  1589. </ul>
  1590. ]]></programlisting>
  1591. </example>
  1592. <example id="zend.view.helpers.initial.navigation.menu.example9">
  1593. <title>
  1594. Rendering only the active branch of a menu with maximum depth
  1595. and no parents
  1596. </title>
  1597. <para>
  1598. </para>
  1599. <programlisting language="php"><![CDATA[
  1600. <?php
  1601. echo $this->navigation()
  1602. ->menu()
  1603. ->setOnlyActiveBranch(true)
  1604. ->setRenderParents(false)
  1605. ->setMaxDepth(1);
  1606. ?>
  1607. Output:
  1608. <ul class="navigation">
  1609. <li class="active">
  1610. <a href="/products/server">Foo Server</a>
  1611. </li>
  1612. <li>
  1613. <a href="/products/studio">Foo Studio</a>
  1614. </li>
  1615. </ul>
  1616. ]]></programlisting>
  1617. </example>
  1618. <example id="zend.view.helpers.initial.navigation.menu.example10">
  1619. <title>Rendering a custom menu using a partial view script</title>
  1620. <para>
  1621. This example shows how to render a custom menu using
  1622. a partial vew script. By calling <methodname>setPartial()</methodname>,
  1623. you can specify a partial view script that will be used
  1624. when calling <methodname>render()</methodname>. When a partial is specified,
  1625. the <methodname>renderPartial()</methodname> method will be called. This
  1626. method will assign the container to the view with the key
  1627. <code>container</code>.
  1628. </para>
  1629. <para>In a layout:</para>
  1630. <programlisting language="php"><![CDATA[
  1631. $partial = array('menu.phtml', 'default');
  1632. $this->navigation()->menu()->setPartial($partial);
  1633. echo $this->navigation()->menu()->render();
  1634. ]]></programlisting>
  1635. <para>In application/modules/default/views/menu.phtml:</para>
  1636. <programlisting language="php"><![CDATA[
  1637. foreach ($this->container as $page) {
  1638. echo $this->navigation()->menu()->htmlify($page), PHP_EOL;
  1639. }
  1640. ]]></programlisting>
  1641. <para>Output:</para>
  1642. <programlisting language="php"><![CDATA[
  1643. <a title="Go Home" href="/">Home</a>
  1644. <a href="/products">Products</a>
  1645. <a title="About us" href="/company/about">Company</a>
  1646. <a href="/community">Community</a>
  1647. ]]></programlisting>
  1648. </example>
  1649. <example id="zend.view.helpers.initial.navigation.menu.example11">
  1650. <title>
  1651. Rendering only the active branch and all siblings of the active branch
  1652. </title>
  1653. <programlisting language="php"><![CDATA[
  1654. echo $this->navigation()
  1655. ->menu()
  1656. ->setExpandSiblingNodesOfActiveBranch(true);
  1657. ]]></programlisting>
  1658. <para>Output:</para>
  1659. <programlisting language="php"><![CDATA[
  1660. <ul class="navigation">
  1661. <li>
  1662. <a title="Go Home" href="/">Home</a>
  1663. </li>
  1664. <li class="active">
  1665. <a href="/products">Products</a>
  1666. <ul>
  1667. <li class="active">
  1668. <a href="/products/server">Foo Server</a>
  1669. <ul>
  1670. <li class="active">
  1671. <a href="/products/server/faq">FAQ</a>
  1672. </li>
  1673. <li>
  1674. <a href="/products/server/editions">Editions</a>
  1675. </li>
  1676. <li>
  1677. <a href="/products/server/requirements">System Requirements</a>
  1678. </li>
  1679. </ul>
  1680. </li>
  1681. <li>
  1682. <a href="/products/studio">Foo Studio</a>
  1683. </li>
  1684. </ul>
  1685. </li>
  1686. <li>
  1687. <a title="About us" href="/company/about">Company</a>
  1688. </li>
  1689. <li>
  1690. <a href="/community">Community</a>
  1691. </li>
  1692. </ul>
  1693. ]]></programlisting>
  1694. </example>
  1695. </sect4>
  1696. <sect4 id="zend.view.helpers.initial.navigation.sitemap">
  1697. <title>Sitemap Helper</title>
  1698. <para>
  1699. The Sitemap helper is used for generating <acronym>XML</acronym> sitemaps, as
  1700. defined by the <ulink
  1701. url="http://www.sitemaps.org/protocol.php">Sitemaps <acronym>XML</acronym>
  1702. format</ulink>. Read more about <ulink
  1703. url="http://en.wikipedia.org/wiki/Sitemaps">Sitemaps on Wikpedia</ulink>.
  1704. </para>
  1705. <para>
  1706. By default, the sitemap helper uses
  1707. <link linkend="zend.validate.sitemap">sitemap validators</link>
  1708. to validate each element that is rendered. This can be disabled by
  1709. calling <code>$helper->setUseSitemapValidators(false)</code>.
  1710. </para>
  1711. <note>
  1712. <para>
  1713. If you disable sitemap validators, the custom properties (see table)
  1714. are not validated at all.
  1715. </para>
  1716. </note>
  1717. <para>
  1718. The sitemap helper also supports <ulink
  1719. url="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">Sitemap XSD
  1720. Schema</ulink> validation of the generated sitemap. This is disabled by default,
  1721. since it will require a request to the Schema file. It can be
  1722. enabled with
  1723. <code>$helper->setUseSchemaValidation(true)</code>.
  1724. </para>
  1725. <table id="zend.view.helpers.initial.navigation.sitemap.elements">
  1726. <title>Sitemap XML elements</title>
  1727. <tgroup cols="2">
  1728. <thead>
  1729. <row>
  1730. <entry>Element</entry>
  1731. <entry>Description</entry>
  1732. </row>
  1733. </thead>
  1734. <tbody>
  1735. <row>
  1736. <entry><code>loc</code></entry>
  1737. <entry>
  1738. Absolute <acronym>URL</acronym> to page. An absolute
  1739. <acronym>URL</acronym> will be generated by the helper.
  1740. </entry>
  1741. </row>
  1742. <row>
  1743. <entry><code>lastmod</code></entry>
  1744. <entry>
  1745. <para>
  1746. The date of last modification of the file, in <ulink
  1747. url="http://www.w3.org/TR/NOTE-datetime">W3C Datetime</ulink>
  1748. format. This time portion can be omitted if desired, and only use
  1749. YYYY-MM-DD.
  1750. </para>
  1751. <para>
  1752. The helper will try to retrieve the
  1753. <code>lastmod</code> value from the page's
  1754. custom property <code>lastmod</code> if it
  1755. is set in the page. If the value is not a
  1756. valid date, it is ignored.
  1757. </para>
  1758. </entry>
  1759. </row>
  1760. <row>
  1761. <entry><code>changefreq</code></entry>
  1762. <entry>
  1763. <para>
  1764. How frequently the page is likely to change.
  1765. This value provides general information to
  1766. search engines and may not correlate exactly
  1767. to how often they crawl the page. Valid
  1768. values are:
  1769. </para>
  1770. <itemizedlist>
  1771. <listitem><para>always</para></listitem>
  1772. <listitem><para>hourly</para></listitem>
  1773. <listitem><para>daily</para></listitem>
  1774. <listitem><para>weekly</para></listitem>
  1775. <listitem><para>monthly</para></listitem>
  1776. <listitem><para>yearly</para></listitem>
  1777. <listitem><para>never</para></listitem>
  1778. </itemizedlist>
  1779. <para>
  1780. The helper will try to retrieve the
  1781. <code>changefreq</code> value from the page's
  1782. custom property <code>changefreq</code> if it
  1783. is set in the page. If the value is not
  1784. valid, it is ignored.
  1785. </para>
  1786. </entry>
  1787. </row>
  1788. <row>
  1789. <entry><code>priority</code></entry>
  1790. <entry>
  1791. <para>
  1792. The priority of this <acronym>URL</acronym> relative to other
  1793. <acronym>URL</acronym>s on your site. Valid values range from
  1794. 0.0 to 1.0.
  1795. </para>
  1796. <para>
  1797. The helper will try to retrieve the
  1798. <code>priority</code> value from the page's
  1799. custom property <code>priority</code> if it
  1800. is set in the page. If the value is not
  1801. valid, it is ignored.
  1802. </para>
  1803. </entry>
  1804. </row>
  1805. </tbody>
  1806. </tgroup>
  1807. </table>
  1808. <para>
  1809. Methods in the sitemap helper:
  1810. </para>
  1811. <itemizedlist>
  1812. <listitem>
  1813. <para>
  1814. <code>{get|set}FormatOutput()</code> gets/sets a flag
  1815. indicating whether <acronym>XML</acronym> output should be formatted. This
  1816. corresponds to the <code>formatOutput</code> property
  1817. of the native <classname>DOMDocument</classname> class.
  1818. Read more at
  1819. <ulink url="http://php.net/domdocument">PHP: DOMDocument - Manual</ulink>.
  1820. Default is <constant>FALSE</constant>.
  1821. </para>
  1822. </listitem>
  1823. <listitem>
  1824. <para>
  1825. <code>{get|set}UseXmlDeclaration()</code> gets/sets a
  1826. flag indicating whether the <acronym>XML</acronym> declaration should be
  1827. included when rendering. Default is <constant>TRUE</constant>.
  1828. </para>
  1829. </listitem>
  1830. <listitem>
  1831. <para>
  1832. <code>{get|set}UseSitemapValidators()</code> gets/sets a
  1833. flag indicating whether sitemap validators should be
  1834. used when generating the DOM sitemap. Default is
  1835. <constant>TRUE</constant>.
  1836. </para>
  1837. </listitem>
  1838. <listitem>
  1839. <para>
  1840. <code>{get|set}UseSchemaValidation()</code> gets/sets a
  1841. flag indicating whether the helper should use <acronym>XML</acronym> Schema
  1842. validation when generating the DOM sitemap. Default is
  1843. <constant>FALSE</constant>. If <constant>TRUE</constant>.
  1844. </para>
  1845. </listitem>
  1846. <listitem>
  1847. <para>
  1848. <code>{get|set}ServerUrl()</code> gets/sets server <acronym>URL</acronym>
  1849. that will be prepended to non-absolute <acronym>URL</acronym>s in the
  1850. <methodname>url()</methodname> method. If no server <acronym>URL</acronym> is
  1851. specified, it will be determined by the helper.
  1852. </para>
  1853. </listitem>
  1854. <listitem>
  1855. <para>
  1856. <methodname>url()</methodname> is used to generate absolute
  1857. <acronym>URL</acronym>s to pages.
  1858. </para>
  1859. </listitem>
  1860. <listitem>
  1861. <para>
  1862. <methodname>getDomSitemap()</methodname> generates a DOMDocument
  1863. from a given container.
  1864. </para>
  1865. </listitem>
  1866. </itemizedlist>
  1867. <example id="zend.view.helpers.initial.navigation.sitemap.example">
  1868. <title>Rendering an XML sitemap</title>
  1869. <para>
  1870. This example shows how to render an <acronym>XML</acronym> sitemap based
  1871. on the setup we did further up.
  1872. </para>
  1873. <programlisting language="php"><![CDATA[
  1874. // In a view script or layout:
  1875. // format output
  1876. $this->navigation()
  1877. ->sitemap()
  1878. ->setFormatOutput(true); // default is false
  1879. // other possible methods:
  1880. // ->setUseXmlDeclaration(false); // default is true
  1881. // ->setServerUrl('http://my.otherhost.com');
  1882. // default is to detect automatically
  1883. // print sitemap
  1884. echo $this->navigation()->sitemap();
  1885. ]]></programlisting>
  1886. <para>
  1887. Notice how pages that are invisible or pages with
  1888. <acronym>ACL</acronym> roles incompatible with the view helper are filtered
  1889. out:
  1890. </para>
  1891. <programlisting language="xml"><![CDATA[
  1892. <?xml version="1.0" encoding="UTF-8"?>
  1893. <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  1894. <url>
  1895. <loc>http://www.example.com/</loc>
  1896. </url>
  1897. <url>
  1898. <loc>http://www.example.com/products</loc>
  1899. </url>
  1900. <url>
  1901. <loc>http://www.example.com/products/server</loc>
  1902. </url>
  1903. <url>
  1904. <loc>http://www.example.com/products/server/faq</loc>
  1905. </url>
  1906. <url>
  1907. <loc>http://www.example.com/products/server/editions</loc>
  1908. </url>
  1909. <url>
  1910. <loc>http://www.example.com/products/server/requirements</loc>
  1911. </url>
  1912. <url>
  1913. <loc>http://www.example.com/products/studio</loc>
  1914. </url>
  1915. <url>
  1916. <loc>http://www.example.com/products/studio/customers</loc>
  1917. </url>
  1918. <url>
  1919. <loc>http://www.example.com/prodcts/studio/support</loc>
  1920. </url>
  1921. <url>
  1922. <loc>http://www.example.com/company/about</loc>
  1923. </url>
  1924. <url>
  1925. <loc>http://www.example.com/company/about/investors</loc>
  1926. </url>
  1927. <url>
  1928. <loc>http://www.example.com/company/news</loc>
  1929. </url>
  1930. <url>
  1931. <loc>http://www.example.com/company/news/press</loc>
  1932. </url>
  1933. <url>
  1934. <loc>http://www.example.com/archive</loc>
  1935. </url>
  1936. <url>
  1937. <loc>http://www.example.com/community</loc>
  1938. </url>
  1939. <url>
  1940. <loc>http://www.example.com/community/account</loc>
  1941. </url>
  1942. <url>
  1943. <loc>http://forums.example.com/</loc>
  1944. </url>
  1945. </urlset>
  1946. ]]></programlisting>
  1947. <para>
  1948. Render the sitemap using no <acronym>ACL</acronym> role (should filter out
  1949. /community/account):
  1950. </para>
  1951. <programlisting language="php"><![CDATA[
  1952. echo $this->navigation()
  1953. ->sitemap()
  1954. ->setFormatOutput(true)
  1955. ->setRole();
  1956. ]]></programlisting>
  1957. <programlisting language="xml"><![CDATA[
  1958. <?xml version="1.0" encoding="UTF-8"?>
  1959. <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  1960. <url>
  1961. <loc>http://www.example.com/</loc>
  1962. </url>
  1963. <url>
  1964. <loc>http://www.example.com/products</loc>
  1965. </url>
  1966. <url>
  1967. <loc>http://www.example.com/products/server</loc>
  1968. </url>
  1969. <url>
  1970. <loc>http://www.example.com/products/server/faq</loc>
  1971. </url>
  1972. <url>
  1973. <loc>http://www.example.com/products/server/editions</loc>
  1974. </url>
  1975. <url>
  1976. <loc>http://www.example.com/products/server/requirements</loc>
  1977. </url>
  1978. <url>
  1979. <loc>http://www.example.com/products/studio</loc>
  1980. </url>
  1981. <url>
  1982. <loc>http://www.example.com/products/studio/customers</loc>
  1983. </url>
  1984. <url>
  1985. <loc>http://www.example.com/prodcts/studio/support</loc>
  1986. </url>
  1987. <url>
  1988. <loc>http://www.example.com/company/about</loc>
  1989. </url>
  1990. <url>
  1991. <loc>http://www.example.com/company/about/investors</loc>
  1992. </url>
  1993. <url>
  1994. <loc>http://www.example.com/company/news</loc>
  1995. </url>
  1996. <url>
  1997. <loc>http://www.example.com/company/news/press</loc>
  1998. </url>
  1999. <url>
  2000. <loc>http://www.example.com/archive</loc>
  2001. </url>
  2002. <url>
  2003. <loc>http://www.example.com/community</loc>
  2004. </url>
  2005. <url>
  2006. <loc>http://forums.example.com/</loc>
  2007. </url>
  2008. </urlset>
  2009. ]]></programlisting>
  2010. <para>
  2011. Render the sitemap using a maximum depth of 1.
  2012. </para>
  2013. <programlisting language="php"><![CDATA[
  2014. echo $this->navigation()
  2015. ->sitemap()
  2016. ->setFormatOutput(true)
  2017. ->setMaxDepth(1);
  2018. ]]></programlisting>
  2019. <programlisting language="xml"><![CDATA[
  2020. <?xml version="1.0" encoding="UTF-8"?>
  2021. <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  2022. <url>
  2023. <loc>http://www.example.com/</loc>
  2024. </url>
  2025. <url>
  2026. <loc>http://www.example.com/products</loc>
  2027. </url>
  2028. <url>
  2029. <loc>http://www.example.com/products/server</loc>
  2030. </url>
  2031. <url>
  2032. <loc>http://www.example.com/products/studio</loc>
  2033. </url>
  2034. <url>
  2035. <loc>http://www.example.com/company/about</loc>
  2036. </url>
  2037. <url>
  2038. <loc>http://www.example.com/company/about/investors</loc>
  2039. </url>
  2040. <url>
  2041. <loc>http://www.example.com/company/news</loc>
  2042. </url>
  2043. <url>
  2044. <loc>http://www.example.com/community</loc>
  2045. </url>
  2046. <url>
  2047. <loc>http://www.example.com/community/account</loc>
  2048. </url>
  2049. <url>
  2050. <loc>http://forums.example.com/</loc>
  2051. </url>
  2052. </urlset>
  2053. ]]></programlisting>
  2054. </example>
  2055. <note>
  2056. <title>UTF-8 encoding used by default</title>
  2057. <para>
  2058. By default, Zend Framework uses <acronym>UTF-8</acronym> as its default encoding,
  2059. and, specific to this case, <classname>Zend_View</classname> does as well. Character
  2060. encoding can be set differently on the view object itself using the
  2061. <methodname>setEncoding()</methodname> method (or the
  2062. <varname>encoding</varname> instantiation parameter). However, since
  2063. <classname>Zend_View_Interface</classname> does not define accessors for encoding,
  2064. it's possible that if you are using a custom view implementation with the Dojo view
  2065. helper, you will not have a <methodname>getEncoding()</methodname> method, which is
  2066. what the view helper uses internally for determining the character set in which to
  2067. encode.
  2068. </para>
  2069. <para>
  2070. If you do not want to utilize <acronym>UTF-8</acronym> in such a situation, you will
  2071. need to implement a <methodname>getEncoding()</methodname> method in your custom
  2072. view implementation.
  2073. </para>
  2074. </note>
  2075. </sect4>
  2076. <sect4 id="zend.view.helpers.initial.navigation.navigation">
  2077. <title>Navigation Helper</title>
  2078. <para>
  2079. The Navigation helper is a proxy helper
  2080. that relays calls to other navigational helpers. It can be
  2081. considered an entry point to all navigation-related view tasks.
  2082. The aforementioned navigational helpers are in the namespace
  2083. <classname>Zend_View_Helper_Navigation</classname>, and would thus require
  2084. the path <code>Zend/View/Helper/Navigation</code> to be added as
  2085. a helper path to the view. With the proxy helper residing in the
  2086. <classname>Zend_View_Helper</classname> namespace, it will always be
  2087. available, without the need to add any helper paths to the view.
  2088. </para>
  2089. <para>
  2090. The Navigation helper finds other helpers that implement the
  2091. <classname>Zend_View_Helper_Navigation_Helper</classname>
  2092. interface, which means custom view helpers can also be proxied.
  2093. This would, however, require that the custom helper path is added
  2094. to the view.
  2095. </para>
  2096. <para>
  2097. When proxying to other helpers, the Navigation helper can inject
  2098. its container, <acronym>ACL</acronym>/role, and translator. This means that you
  2099. won't have to explicitly set all three in all navigational
  2100. helpers, nor resort to injecting by means of
  2101. <classname>Zend_Registry</classname> or static methods.
  2102. </para>
  2103. <itemizedlist>
  2104. <listitem>
  2105. <para>
  2106. <methodname>findHelper()</methodname> finds the given helper,
  2107. verifies that it is a navigational helper, and injects
  2108. container, <acronym>ACL</acronym>/role and translator.
  2109. </para>
  2110. </listitem>
  2111. <listitem>
  2112. <para>
  2113. <code>{get|set}InjectContainer()</code> gets/sets a flag
  2114. indicating whether the container should be injected to
  2115. proxied helpers. Default is <constant>TRUE</constant>.
  2116. </para>
  2117. </listitem>
  2118. <listitem>
  2119. <para>
  2120. <code>{get|set}InjectAcl()</code> gets/sets a flag
  2121. indicating whether the <acronym>ACL</acronym>/role should be injected to
  2122. proxied helpers. Default is <constant>TRUE</constant>.
  2123. </para>
  2124. </listitem>
  2125. <listitem>
  2126. <para>
  2127. <code>{get|set}InjectTranslator()</code> gets/sets a flag
  2128. indicating whether the translator should be injected to
  2129. proxied helpers. Default is <constant>TRUE</constant>.
  2130. </para>
  2131. </listitem>
  2132. <listitem>
  2133. <para>
  2134. <code>{get|set}DefaultProxy()</code> gets/sets the default
  2135. proxy. Default is <code>'menu'</code>.
  2136. </para>
  2137. </listitem>
  2138. <listitem>
  2139. <para>
  2140. <methodname>render()</methodname> proxies to the render method of
  2141. the default proxy.
  2142. </para>
  2143. </listitem>
  2144. </itemizedlist>
  2145. </sect4>
  2146. </sect3>