Zend_View-Helpers-Navigation.xml 80 KB

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