Zend_View-Helpers-Navigation.xml 82 KB

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