Zend_View-Helpers-Navigation.xml 80 KB

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