Zend_View-Helpers-Navigation.xml 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect3 id="zend.view.helpers.initial.navigation">
  4. <title>Navigation Helpers</title>
  5. <para>
  6. The navigation helpers are used for rendering navigational elements
  7. from <link linkend="zend.navigation.containers">Zend_Navigation_Container</link>
  8. instances.
  9. </para>
  10. <para>
  11. There are 5 built-in helpers:
  12. </para>
  13. <itemizedlist>
  14. <listitem>
  15. <para>
  16. <link
  17. linkend="zend.view.helpers.initial.navigation.breadcrumbs">Breadcrumbs</link>,
  18. used for rendering the path to the currently active page.
  19. </para>
  20. </listitem>
  21. <listitem>
  22. <para>
  23. <link linkend="zend.view.helpers.initial.navigation.links">Links</link>,
  24. used for rendering navigational head links (e.g.
  25. <code>&lt;link rel="next" href="..." /&gt;</code>)
  26. </para>
  27. </listitem>
  28. <listitem>
  29. <para>
  30. <link linkend="zend.view.helpers.initial.navigation.menu">Menu</link>,
  31. used for rendering menus.
  32. </para>
  33. </listitem>
  34. <listitem>
  35. <para>
  36. <link linkend="zend.view.helpers.initial.navigation.sitemap">Sitemap</link>,
  37. used for rendering sitemaps conforming to the
  38. <ulink url="http://www.sitemaps.org/protocol.php">Sitemaps <acronym>XML</acronym> format</ulink>.
  39. </para>
  40. </listitem>
  41. <listitem>
  42. <para>
  43. <link
  44. linkend="zend.view.helpers.initial.navigation.navigation">Navigation</link>,
  45. used for proxying calls to other navigational helpers.
  46. </para>
  47. </listitem>
  48. </itemizedlist>
  49. <para>
  50. All built-in helpers extend
  51. <classname>Zend_View_Helper_Navigation_HelperAbstract</classname>, which
  52. adds integration with <link linkend="zend.acl">ACL</link> and
  53. <link linkend="zend.translate">translation</link>. The abstract class
  54. implements the interface
  55. <classname>Zend_View_Helper_Navigation_Helper</classname>, which
  56. defines the following methods:
  57. </para>
  58. <itemizedlist>
  59. <listitem>
  60. <para>
  61. <code>{get|set}Container()</code> gets/sets the navigation
  62. container the helper should operate on by default, and
  63. <methodname>hasContainer()</methodname> checks if the helper
  64. has container registered.
  65. </para>
  66. </listitem>
  67. <listitem>
  68. <para>
  69. <code>{get|set}Translator()</code> gets/sets the
  70. translator used for translating labels and titles, and
  71. <code>{get|set}UseTranslator()</code> controls whether
  72. the translator should be enabled. The method
  73. <methodname>hasTranslator()</methodname> checks if the helper has
  74. a translator registered.
  75. </para>
  76. </listitem>
  77. <listitem>
  78. <para>
  79. <code>{get|set}Acl()</code>, <code>{get|set}Role()</code>,
  80. gets/sets <acronym>ACL</acronym> (<classname>Zend_Acl</classname>) instance and
  81. role (<type>String</type> or
  82. <classname>Zend_Acl_Role_Interface</classname>) used for
  83. filtering out pages when rendering, and
  84. <code>{get|set}UseAcl()</code> controls whether <acronym>ACL</acronym> should
  85. be enabled. The methods <methodname>hasAcl()</methodname> and
  86. <methodname>hasRole()</methodname> checks if the helper has an <acronym>ACL</acronym>
  87. instance or a role registered.
  88. </para>
  89. </listitem>
  90. <listitem>
  91. <para>
  92. <methodname>__toString()</methodname>, magic method to ensure that
  93. helpers can be rendered by <code>echo</code>ing the
  94. helper instance directly.
  95. </para>
  96. </listitem>
  97. <listitem>
  98. <para>
  99. <methodname>render()</methodname>, must be implemented by concrete
  100. helpers to do the actual rendering.
  101. </para>
  102. </listitem>
  103. </itemizedlist>
  104. <para>
  105. In addition to the method stubs from the interface, the abstract
  106. class also implements the following methods:
  107. </para>
  108. <itemizedlist>
  109. <listitem>
  110. <para>
  111. <code>{get|set}Indent()</code> gets/set indentation. The
  112. setter accepts a <type>String</type> or an <code>int</code>.
  113. In the case of an <code>int</code>, the helper will use
  114. the given number of spaces for indentation. I.e.,
  115. <methodname>setIndent(4)</methodname> means 4 initial spaces of
  116. indentation. Indentation can be specified for all helpers
  117. except the Sitemap helper.
  118. </para>
  119. </listitem>
  120. <listitem>
  121. <para>
  122. <code>{get|set}MinDepth()</code> gets/set the minimum depth
  123. a page must have to be included by the helper. Setting
  124. <constant>NULL</constant> means no minimum depth.
  125. </para>
  126. </listitem>
  127. <listitem>
  128. <para>
  129. <code>{get|set}MaxDepth()</code> gets/set the maximum depth
  130. a page can have to be included by the helper. Setting
  131. <constant>NULL</constant> means no maximum depth.
  132. </para>
  133. </listitem>
  134. <listitem>
  135. <para>
  136. <code>{get|set}RenderInvisible()</code> gets/set whether to
  137. render items that have been marked as invisible or not.
  138. </para>
  139. </listitem>
  140. <listitem>
  141. <para>
  142. <methodname>__call()</methodname> is used for proxying calls to the
  143. container registered in the helper, which means you can
  144. call methods on a helper as if it was a container. See <link
  145. linkend="zend.view.helpers.initial.navigation.proxy.example">example</link>
  146. below.
  147. </para>
  148. </listitem>
  149. <listitem>
  150. <para>
  151. <methodname>findActive($container, $minDepth, $maxDepth)</methodname>
  152. is used for finding the deepest active page in the given
  153. container. If depths are not given, the method will use
  154. the values retrieved from <methodname>getMinDepth()</methodname> and
  155. <methodname>getMaxDepth()</methodname>. The deepest active page must
  156. be between <varname>$minDepth</varname> and <varname>$maxDepth</varname>
  157. inclusively. Returns an array containing a reference to the
  158. found page instance and the depth at which the page was
  159. found.
  160. </para>
  161. </listitem>
  162. <listitem>
  163. <para>
  164. <methodname>htmlify()</methodname> renders an <code>a</code> HTML
  165. element from a <classname>Zend_Navigation_Page</classname>
  166. instance.
  167. </para>
  168. </listitem>
  169. <listitem>
  170. <para>
  171. <methodname>accept()</methodname> is used for determining if a page
  172. should be accepted when iterating containers. This method
  173. checks for page visibility and verifies that the helper's
  174. role is allowed access to the page's resource/privilege.
  175. </para>
  176. </listitem>
  177. <listitem>
  178. <para>
  179. <code>static setDefaultAcl()</code> is used for setting
  180. a defualt <acronym>ACL</acronym> object that will be used by helpers.
  181. </para>
  182. </listitem>
  183. <listitem>
  184. <para>
  185. <code>static setDefaultRole()</code> is used for setting
  186. a default <acronym>ACL</acronym> that will be used by helpers
  187. </para>
  188. </listitem>
  189. </itemizedlist>
  190. <para>
  191. If a navigation container is not explicitly set in a helper using
  192. <code>$helper->setContainer($nav)</code>, the helper will look
  193. for a container instance with the key <classname>Zend_Navigation</classname> in
  194. <link linkend="zend.registry">the registry</link>.
  195. If a container is not explicitly set or found in the registry, the
  196. helper will create an empty <classname>Zend_Navigation</classname>
  197. container when calling <code>$helper->getContainer()</code>.
  198. </para>
  199. <example id="zend.view.helpers.initial.navigation.proxy.example">
  200. <title>Proxying calls to the navigation container</title>
  201. <para>
  202. Navigation view helpers use the magic method <methodname>__call()</methodname>
  203. to proxy method calls to the navigation container that is
  204. registered in the view helper.
  205. </para>
  206. <programlisting language="php"><![CDATA[
  207. $this->navigation()->addPage(array(
  208. 'type' => 'uri',
  209. 'label' => 'New page'));
  210. ]]></programlisting>
  211. <para>
  212. The call above will add a page to the container in the
  213. <classname>Navigation</classname> helper.
  214. </para>
  215. </example>
  216. <sect4 id="zend.view.helpers.initial.navigation.i18n">
  217. <title>Translation of labels and titles</title>
  218. <para>
  219. The navigation helpers support translation of page labels and titles.
  220. You can set a translator of type <classname>Zend_Translate</classname>
  221. or <classname>Zend_Translate_Adapter</classname> in the helper using
  222. <code>$helper->setTranslator($translator)</code>, or like with other
  223. I18n-enabled components; by adding the translator to
  224. <link linkend="zend.registry">the registry</link> by using the key
  225. <classname>Zend_Translate</classname>.
  226. </para>
  227. <para>
  228. If you want to disable translation, use <code>$helper->setUseTranslator(false)</code>.
  229. </para>
  230. <para>
  231. The
  232. <link linkend="zend.view.helpers.initial.navigation.navigation">proxy
  233. helper</link> will inject its own translator to the helper it
  234. proxies to if the proxied helper doesn't already have a translator.
  235. </para>
  236. <note>
  237. <para>
  238. There is no translation in the sitemap helper, since there
  239. are no page labels or titles involved in an <acronym>XML</acronym> sitemap.
  240. </para>
  241. </note>
  242. </sect4>
  243. <sect4 id="zend.view.helpers.initial.navigation.acl">
  244. <title>Integration with ACL</title>
  245. <para>
  246. All navigational view helpers support <acronym>ACL</acronym> inherently from the
  247. class <classname>Zend_View_Helper_Navigation_HelperAbstract</classname>.
  248. A <classname>Zend_Acl</classname> object can be assigned to
  249. a helper instance with <code>$helper->setAcl($acl)</code>, and role
  250. with <code>$helper->setRole('member')</code> or
  251. <code>$helper->setRole(new Zend_Acl_Role('member'))</code> . If <acronym>ACL</acronym>
  252. is used in the helper, the role in the helper must be allowed by
  253. the <acronym>ACL</acronym> to access a page's <code>resource</code> and/or have the
  254. page's <code>privilege</code> for the page to be included when
  255. rendering.
  256. </para>
  257. <para>
  258. If a page is not accepted by <acronym>ACL</acronym>, any descendant page will also
  259. be excluded from rendering.
  260. </para>
  261. <para>
  262. The
  263. <link linkend="zend.view.helpers.initial.navigation.navigation">proxy
  264. helper</link> will inject its own <acronym>ACL</acronym> and role to the helper it
  265. proxies to if the proxied helper doesn't already have any.
  266. </para>
  267. <para>
  268. The examples below all show how <acronym>ACL</acronym> affects rendering.
  269. </para>
  270. </sect4>
  271. <sect4 id="zend.view.helpers.initial.navigation.setup">
  272. <title>Navigation setup used in examples</title>
  273. <para>
  274. This example shows the setup of a navigation container for a
  275. fictional software company.
  276. </para>
  277. <para>
  278. Notes on the setup:
  279. </para>
  280. <itemizedlist>
  281. <listitem>
  282. <para>
  283. The domain for the site is <code>www.example.com</code>.
  284. </para>
  285. </listitem>
  286. <listitem>
  287. <para>
  288. Interesting page properties are marked with a comment.
  289. </para>
  290. </listitem>
  291. <listitem>
  292. <para>
  293. Unless otherwise is stated in other examples, the user
  294. is requesting the <acronym>URL</acronym>
  295. <code>http://www.example.com/products/server/faq/</code>,
  296. which translates to the page labeled <constant>FAQ</constant>
  297. under <code>Foo Server</code>.
  298. </para>
  299. </listitem>
  300. <listitem>
  301. <para>
  302. The assumed <acronym>ACL</acronym> and router setup is shown below the
  303. container setup.
  304. </para>
  305. </listitem>
  306. </itemizedlist>
  307. <programlisting language="php"><![CDATA[
  308. /*
  309. * Navigation container (config/array)
  310. * Each element in the array will be passed to
  311. * Zend_Navigation_Page::factory() when constructing
  312. * the navigation container below.
  313. */
  314. $pages = array(
  315. array(
  316. 'label' => 'Home',
  317. 'title' => 'Go Home',
  318. 'module' => 'default',
  319. 'controller' => 'index',
  320. 'action' => 'index',
  321. 'order' => -100 // make sure home is the first page
  322. ),
  323. array(
  324. 'label' => 'Special offer this week only!',
  325. 'module' => 'store',
  326. 'controller' => 'offer',
  327. 'action' => 'amazing',
  328. 'visible' => false // not visible
  329. ),
  330. array(
  331. 'label' => 'Products',
  332. 'module' => 'products',
  333. 'controller' => 'index',
  334. 'action' => 'index',
  335. 'pages' => array(
  336. array(
  337. 'label' => 'Foo Server',
  338. 'module' => 'products',
  339. 'controller' => 'server',
  340. 'action' => 'index',
  341. 'pages' => array(
  342. array(
  343. 'label' => 'FAQ',
  344. 'module' => 'products',
  345. 'controller' => 'server',
  346. 'action' => 'faq',
  347. 'rel' => array(
  348. 'canonical' => 'http://www.example.com/?page=faq',
  349. 'alternate' => array(
  350. 'module' => 'products',
  351. 'controller' => 'server',
  352. 'action' => 'faq',
  353. 'params' => array('format' => 'xml')
  354. )
  355. )
  356. ),
  357. array(
  358. 'label' => 'Editions',
  359. 'module' => 'products',
  360. 'controller' => 'server',
  361. 'action' => 'editions'
  362. ),
  363. array(
  364. 'label' => 'System Requirements',
  365. 'module' => 'products',
  366. 'controller' => 'server',
  367. 'action' => 'requirements'
  368. )
  369. )
  370. ),
  371. array(
  372. 'label' => 'Foo Studio',
  373. 'module' => 'products',
  374. 'controller' => 'studio',
  375. 'action' => 'index',
  376. 'pages' => array(
  377. array(
  378. 'label' => 'Customer Stories',
  379. 'module' => 'products',
  380. 'controller' => 'studio',
  381. 'action' => 'customers'
  382. ),
  383. array(
  384. 'label' => 'Support',
  385. 'module' => 'prodcts',
  386. 'controller' => 'studio',
  387. 'action' => 'support'
  388. )
  389. )
  390. )
  391. )
  392. ),
  393. array(
  394. 'label' => 'Company',
  395. 'title' => 'About us',
  396. 'module' => 'company',
  397. 'controller' => 'about',
  398. 'action' => 'index',
  399. 'pages' => array(
  400. array(
  401. 'label' => 'Investor Relations',
  402. 'module' => 'company',
  403. 'controller' => 'about',
  404. 'action' => 'investors'
  405. ),
  406. array(
  407. 'label' => 'News',
  408. 'class' => 'rss', // class
  409. 'module' => 'company',
  410. 'controller' => 'news',
  411. 'action' => 'index',
  412. 'pages' => array(
  413. array(
  414. 'label' => 'Press Releases',
  415. 'module' => 'company',
  416. 'controller' => 'news',
  417. 'action' => 'press'
  418. ),
  419. array(
  420. 'label' => 'Archive',
  421. 'route' => 'archive', // route
  422. 'module' => 'company',
  423. 'controller' => 'news',
  424. 'action' => 'archive'
  425. )
  426. )
  427. )
  428. )
  429. ),
  430. array(
  431. 'label' => 'Community',
  432. 'module' => 'community',
  433. 'controller' => 'index',
  434. 'action' => 'index',
  435. 'pages' => array(
  436. array(
  437. 'label' => 'My Account',
  438. 'module' => 'community',
  439. 'controller' => 'account',
  440. 'action' => 'index',
  441. 'resource' => 'mvc:community.account' // resource
  442. ),
  443. array(
  444. 'label' => 'Forums',
  445. 'uri' => 'http://forums.example.com/',
  446. 'class' => 'external' // class
  447. )
  448. )
  449. ),
  450. array(
  451. 'label' => 'Administration',
  452. 'module' => 'admin',
  453. 'controller' => 'index',
  454. 'action' => 'index',
  455. 'resource' => 'mvc:admin', // resource
  456. 'pages' => array(
  457. array(
  458. 'label' => 'Write new article',
  459. 'module' => 'admin',
  460. 'controller' => 'post',
  461. 'aciton' => 'write'
  462. )
  463. )
  464. )
  465. );
  466. // Create container from array
  467. $container = new Zend_Navigation($pages);
  468. // Store the container in the proxy helper:
  469. $view->getHelper('navigation')->setContainer($container);
  470. // ...or simply:
  471. $view->navigation($container);
  472. // ...or store it in the reigstry:
  473. Zend_Registry::set('Zend_Navigation', $container);
  474. ]]></programlisting>
  475. <para>
  476. In addition to the container above, the following setup is assumed:
  477. </para>
  478. <programlisting language="php"><![CDATA[
  479. // Setup router (default routes and 'archive' route):
  480. $front = Zend_Controller_Front::getInstance();
  481. $router = $front->getRouter();
  482. $router->addDefaultRoutes();
  483. $router->addRoute(
  484. 'archive',
  485. new Zend_Controller_Router_Route(
  486. '/archive/:year',
  487. array(
  488. 'module' => 'company',
  489. 'controller' => 'news',
  490. 'action' => 'archive',
  491. 'year' => (int) date('Y') - 1
  492. ),
  493. array('year' => '\d+')
  494. )
  495. );
  496. // Setup ACL:
  497. $acl = new Zend_Acl();
  498. $acl->addRole(new Zend_Acl_Role('member'));
  499. $acl->addRole(new Zend_Acl_Role('admin'));
  500. $acl->add(new Zend_Acl_Resource('mvc:admin'));
  501. $acl->add(new Zend_Acl_Resource('mvc:community.account'));
  502. $acl->allow('member', 'mvc:community.account');
  503. $acl->allow('admin', null);
  504. // Store ACL and role in the proxy helper:
  505. $view->navigation()->setAcl($acl)->setRole('member');
  506. // ...or set default ACL and role statically:
  507. Zend_View_Helper_Navigation_HelperAbstract::setDefaultAcl($acl);
  508. Zend_View_Helper_Navigation_HelperAbstract::setDefaultRole('member');
  509. ]]></programlisting>
  510. </sect4>
  511. <sect4 id="zend.view.helpers.initial.navigation.breadcrumbs">
  512. <title>Breadcrumbs Helper</title>
  513. <para>
  514. Breadcrumbs are used for indicating where in a sitemap
  515. a user is currently browsing, and are typically rendered
  516. like this: "You are here: Home > Products > FantasticProduct 1.0".
  517. The breadcrumbs helper follows the guidelines from <ulink
  518. url="http://developer.yahoo.com/ypatterns/pattern.php?pattern=breadcrumbs">Breadcrumbs
  519. Pattern - Yahoo! Design Pattern Library</ulink>,
  520. and allows simple customization (minimum/maximum depth, indentation,
  521. separator, and whether the last element should be linked), or
  522. rendering using a partial view script.
  523. </para>
  524. <para>
  525. The Breadcrumbs helper works like this; it finds the deepest active
  526. page in a navigation container, and renders an upwards path to
  527. the root. For <acronym>MVC</acronym> pages, the "activeness" of a page is
  528. determined by inspecting the request object, as stated in the
  529. section on <link linkend="zend.navigation.pages.mvc">Zend_Navigation_Page_Mvc</link>.
  530. </para>
  531. <para>
  532. The helper sets the <code>minDepth</code> property to 1 by default,
  533. meaning breadcrumbs will not be rendered if the deepest active page
  534. is a root page. If <code>maxDepth</code> is specified, the helper
  535. will stop rendering when at the specified depth (e.g. stop at level
  536. 2 even if the deepest active page is on level 3).
  537. </para>
  538. <para>
  539. Methods in the breadcrumbs helper:
  540. </para>
  541. <itemizedlist>
  542. <listitem>
  543. <para>
  544. <code>{get|set}Separator()</code> gets/sets separator
  545. string that is used between breadcrumbs. Defualt is
  546. <code>' &amp;gt; '</code>.
  547. </para>
  548. </listitem>
  549. <listitem>
  550. <para>
  551. <code>{get|set}LinkLast()</code> gets/sets whether the
  552. last breadcrumb should be rendered as an anchor or not.
  553. Default is <constant>FALSE</constant>.
  554. </para>
  555. </listitem>
  556. <listitem>
  557. <para>
  558. <code>{get|set}Partial()</code> gets/sets a partial view
  559. script that should be used for rendering breadcrumbs.
  560. If a partial view script is set, the helper's
  561. <methodname>render()</methodname> method will use the
  562. <methodname>renderPartial()</methodname> method. If no partial is
  563. set, the <methodname>renderStraight()</methodname> method is used.
  564. The helper expects the partial to be a <type>String</type>
  565. or an <type>Array</type> with two elements. If the partial
  566. is a <type>String</type>, it denotes the name of the partial
  567. script to use. If it is an <type>Array</type>, the first
  568. element will be used as the name of the partial view
  569. script, and the second element is the module where the
  570. script is found.
  571. </para>
  572. </listitem>
  573. <listitem>
  574. <para>
  575. <methodname>renderStraight()</methodname> is the default render
  576. method.
  577. </para>
  578. </listitem>
  579. <listitem>
  580. <para>
  581. <methodname>renderPartial()</methodname> is used for rendering
  582. using a partial view script.
  583. </para>
  584. </listitem>
  585. </itemizedlist>
  586. <example id="zend.view.helpers.initial.navigation.breadcrumbs.example1">
  587. <title>Rendering breadcrumbs</title>
  588. <para>
  589. This example shows how to render breadcrumbs with default
  590. settings.
  591. </para>
  592. <programlisting language="php"><![CDATA[
  593. In a view script or layout:
  594. <?php echo $this->navigation()->breadcrumbs(); ?>
  595. or if short tags are enabled:
  596. <?= $this->navigation()->breadcrumbs(); ?>
  597. The two calls above take advantage of the magic __toString() method,
  598. and are equivalent to:
  599. <?php echo $this->navigation()->breadcrumbs()->render(); ?>
  600. Output:
  601. <a href="/products">Products</a> &gt; <a href="/products/server">Foo Server</a> &gt; FAQ
  602. ]]></programlisting>
  603. </example>
  604. <example id="zend.view.helpers.initial.navigation.breadcrumbs.example2">
  605. <title>Specifying indentation</title>
  606. <para>
  607. This example shows how to render breadcrumbs with initial
  608. indentation.
  609. </para>
  610. <programlisting language="php"><![CDATA[
  611. Rendering with 8 spaces indentation:
  612. <?php echo $this->navigation()->breadcrumbs()->setIndent(8);?>
  613. Output:
  614. <a href="/products">Products</a> &gt; <a href="/products/server">Foo Server</a> &gt; FAQ
  615. ]]></programlisting>
  616. </example>
  617. <example id="zend.view.helpers.initial.navigation.breadcrumbs.example3">
  618. <title>Customize breadcrumbs output</title>
  619. <para>
  620. This example shows how to customze breadcrumbs output by
  621. specifying various options.
  622. </para>
  623. <programlisting language="php"><![CDATA[
  624. In a view script or layout:
  625. <?php
  626. echo $this->navigation()
  627. ->breadcrumbs()
  628. ->setLinkLast(true) // link last page
  629. ->setMaxDepth(1) // stop at level 1
  630. ->setSeparator(' &#9654;' . PHP_EOL); // cool separator with newline
  631. ?>
  632. Output:
  633. <a href="/products">Products</a> &#9654;
  634. <a href="/products/server">Foo Server</a>
  635. /////////////////////////////////////////////////////
  636. Setting minimum depth required to render breadcrumbs:
  637. <?php
  638. $this->navigation()->breadcrumbs()->setMinDepth(10);
  639. echo $this->navigation()->breadcrumbs();
  640. ?>
  641. Output:
  642. Nothing, because the deepest active page is not at level 10 or deeper.
  643. ]]></programlisting>
  644. </example>
  645. <example id="zend.view.helpers.initial.navigation.breadcrumbs.example4">
  646. <title>Rendering breadcrumbs using a partial view script</title>
  647. <para>
  648. This example shows how to render customized breadcrumbs using
  649. a partial vew script. By calling <methodname>setPartial()</methodname>,
  650. you can specify a partial view script that will be used
  651. when calling <methodname>render()</methodname>. When a partial is specified,
  652. the <methodname>renderPartial()</methodname> method will be called. This
  653. method will find the deepest active page and pass an array
  654. of pages that leads to the active page to the partial view
  655. script.
  656. </para>
  657. <para>
  658. In a layout:
  659. </para>
  660. <programlisting language="php"><![CDATA[
  661. $partial = ;
  662. echo $this->navigation()->breadcrumbs()
  663. ->setPartial(array('breadcrumbs.phtml', 'default'));
  664. ]]></programlisting>
  665. <para>
  666. Contents of
  667. <code>application/modules/default/views/breadcrumbs.phtml</code>:
  668. </para>
  669. <programlisting language="php"><![CDATA[
  670. echo implode(', ', array_map(
  671. create_function('$a', 'return $a->getLabel();'),
  672. $this->pages));
  673. ]]></programlisting>
  674. <para>
  675. Output:
  676. </para>
  677. <programlisting language="php"><![CDATA[
  678. Products, Foo Server, FAQ
  679. ]]></programlisting>
  680. </example>
  681. </sect4>
  682. <sect4 id="zend.view.helpers.initial.navigation.links">
  683. <title>Links Helper</title>
  684. <para>
  685. The links helper is used for rendering HTML <constant>LINK</constant>
  686. elements. Links are used for describing document relationships
  687. of the currently active page. Read more about links and link
  688. types at <ulink url="http://www.w3.org/TR/html4/struct/links.html#h-12.3">Document
  689. relationships: the LINK element (HTML4 W3C Rec.)</ulink>
  690. and <ulink
  691. url="http://www.w3.org/TR/html4/types.html#h-6.12">Link types (HTML4 W3C
  692. Rec.)</ulink> in the HTML4 W3C Recommendation.
  693. </para>
  694. <para>
  695. There are two types of relations; forward and reverse, indicated
  696. by the keyords <code>'rel'</code> and <code>'rev'</code>. Most
  697. methods in the helper will take a <varname>$rel</varname> param, which
  698. must be either <code>'rel'</code> or <code>'rev'</code>. Most
  699. methods also take a <varname>$type</varname> param, which is used
  700. for specifying the link type (e.g. alternate, start, next, prev,
  701. chapter, etc).
  702. </para>
  703. <para>
  704. Relationships can be added to page objects manually, or found
  705. by traversing the container registered in the helper. The method
  706. <methodname>findRelation($page, $rel, $type)</methodname> will first try
  707. to find the given <varname>$rel</varname> of <varname>$type</varname> from
  708. the <varname>$page</varname> by calling <code>$page->findRel($type)</code>
  709. or <code>$page->findRel($type)</code>. If the <varname>$page</varname>
  710. has a relation that can be converted to a page instance, that
  711. relation will be used. If the <varname>$page</varname> instance doesn't
  712. have the specified <varname>$type</varname>, the helper will look for
  713. a method in the helper named <code>search$rel$type</code> (e.g.
  714. <methodname>searchRelNext()</methodname> or
  715. <methodname>searchRevAlternate()</methodname>).
  716. If such a method exists, it will be used for determining the
  717. <varname>$page</varname>'s relation by traversing the container.
  718. </para>
  719. <para>
  720. Not all relations can be determined by traversing the container.
  721. These are the relations that will be found by searching:
  722. </para>
  723. <itemizedlist>
  724. <listitem>
  725. <para>
  726. <methodname>searchRelStart()</methodname>, forward 'start'
  727. relation: the first page in the container.
  728. </para>
  729. </listitem>
  730. <listitem>
  731. <para>
  732. <methodname>searchRelNext()</methodname>, forward 'next'
  733. relation; finds the next page in the container, i.e.
  734. the page after the active page.
  735. </para>
  736. </listitem>
  737. <listitem>
  738. <para>
  739. <methodname>searchRelPrev()</methodname>, forward 'prev'
  740. relation; finds the previous page, i.e. the page before
  741. the active page.
  742. </para>
  743. </listitem>
  744. <listitem>
  745. <para>
  746. <methodname>searchRelChapter()</methodname>, forward 'chapter'
  747. relations; finds all pages on level 0 except the 'start'
  748. relation or the active page if it's on level 0.
  749. </para>
  750. </listitem>
  751. <listitem>
  752. <para>
  753. <methodname>searchRelSection()</methodname>, forward 'section'
  754. relations; finds all child pages of the active page if
  755. the active page is on level 0 (a 'chapter').
  756. </para>
  757. </listitem>
  758. <listitem>
  759. <para>
  760. <methodname>searchRelSubsection()</methodname>, forward 'subsection'
  761. relations; finds all child pages of the active page if
  762. the active pages is on level 1 (a 'section').
  763. </para>
  764. </listitem>
  765. <listitem>
  766. <para>
  767. <methodname>searchRevSection()</methodname>, reverse 'section'
  768. relation; finds the parent of the active page if the
  769. active page is on level 1 (a 'section').
  770. </para>
  771. </listitem>
  772. <listitem>
  773. <para>
  774. <methodname>searchRevSubsection()</methodname>, reverse 'subsection'
  775. relation; finds the parent of the active page if the
  776. active page is on level 2 (a 'subsection').
  777. </para>
  778. </listitem>
  779. </itemizedlist>
  780. <note>
  781. <para>
  782. When looking for relations in the page instance
  783. (<code>$page->getRel($type)</code> or
  784. <code>$page->getRev($type)</code>), the helper accepts the
  785. values of type <type>String</type>, <type>Array</type>,
  786. <classname>Zend_Config</classname>, or
  787. <classname>Zend_Navigation_Page</classname>. If a string
  788. is found, it will be converted to a
  789. <classname>Zend_Navigation_Page_Uri</classname>. If an array
  790. or a config is found, it will be converted to one or several
  791. page instances. If the first key of the array/config is numeric,
  792. it will be considered to contain several pages, and each
  793. element will be passed to the
  794. <link linkend="zend.navigation.pages.factory">page factory</link>.
  795. If the first key is not numeric, the array/config will be
  796. passed to the page factory directly, and a single page will
  797. be returned.
  798. </para>
  799. </note>
  800. <para>
  801. The helper also supports magic methods for finding relations.
  802. E.g. to find forward alternate relations, call
  803. <code>$helper->findRelAlternate($page)</code>, and to find
  804. reverse section relations, call
  805. <code>$helper->findRevSection($page)</code>. Those calls correspond
  806. to <code>$helper->findRelation($page, 'rel', 'alternate');</code>
  807. and <code>$helper->findRelation($page, 'rev', 'section');</code>
  808. respectively.
  809. </para>
  810. <para>
  811. To customize which relations should be rendered, the helper
  812. uses a render flag. The render flag is an integer value, and will be
  813. used in a
  814. <ulink url="http://php.net/manual/en/language.operators.bitwise.php">bitwse
  815. <code>and</code> (<code>&amp;</code>) operation</ulink> against the
  816. helper's render constants to determine if the relation that belongs
  817. to the render constant should be rendered.
  818. </para>
  819. <para>
  820. See the
  821. <link linkend="zend.view.helpers.initial.navigation.links.example3">example
  822. below</link> for more information.
  823. </para>
  824. <itemizedlist>
  825. <listitem>
  826. <para>
  827. <constant>Zend_View_Helper_Navigation_Link::RENDER_ALTERNATE</constant>
  828. </para>
  829. </listitem>
  830. <listitem>
  831. <para>
  832. <constant>Zend_View_Helper_Navigation_Link::RENDER_STYLESHEET</constant>
  833. </para>
  834. </listitem>
  835. <listitem>
  836. <para>
  837. <constant>Zend_View_Helper_Navigation_Link::RENDER_START</constant>
  838. </para>
  839. </listitem>
  840. <listitem>
  841. <para>
  842. <constant>Zend_View_Helper_Navigation_Link::RENDER_NEXT</constant>
  843. </para>
  844. </listitem>
  845. <listitem>
  846. <para>
  847. <constant>Zend_View_Helper_Navigation_Link::RENDER_PREV</constant>
  848. </para>
  849. </listitem>
  850. <listitem>
  851. <para>
  852. <constant>Zend_View_Helper_Navigation_Link::RENDER_CONTENTS</constant>
  853. </para>
  854. </listitem>
  855. <listitem>
  856. <para>
  857. <constant>Zend_View_Helper_Navigation_Link::RENDER_INDEX</constant>
  858. </para>
  859. </listitem>
  860. <listitem>
  861. <para>
  862. <constant>Zend_View_Helper_Navigation_Link::RENDER_GLOSSARY</constant>
  863. </para>
  864. </listitem>
  865. <listitem>
  866. <para>
  867. <constant>Zend_View_Helper_Navigation_Link::RENDER_COPYRIGHT</constant>
  868. </para>
  869. </listitem>
  870. <listitem>
  871. <para>
  872. <constant>Zend_View_Helper_Navigation_Link::RENDER_CHAPTER</constant>
  873. </para>
  874. </listitem>
  875. <listitem>
  876. <para>
  877. <constant>Zend_View_Helper_Navigation_Link::RENDER_SECTION</constant>
  878. </para>
  879. </listitem>
  880. <listitem>
  881. <para>
  882. <constant>Zend_View_Helper_Navigation_Link::RENDER_SUBSECTION</constant>
  883. </para>
  884. </listitem>
  885. <listitem>
  886. <para>
  887. <constant>Zend_View_Helper_Navigation_Link::RENDER_APPENDIX</constant>
  888. </para>
  889. </listitem>
  890. <listitem>
  891. <para>
  892. <constant>Zend_View_Helper_Navigation_Link::RENDER_HELP</constant>
  893. </para>
  894. </listitem>
  895. <listitem>
  896. <para>
  897. <constant>Zend_View_Helper_Navigation_Link::RENDER_BOOKMARK</constant>
  898. </para>
  899. </listitem>
  900. <listitem>
  901. <para>
  902. <constant>Zend_View_Helper_Navigation_Link::RENDER_CUSTOM</constant>
  903. </para>
  904. </listitem>
  905. <listitem>
  906. <para>
  907. <constant>Zend_View_Helper_Navigation_Link::RENDER_ALL</constant>
  908. </para>
  909. </listitem>
  910. </itemizedlist>
  911. <para>
  912. The constants from <constant>RENDER_ALTERNATE</constant> to
  913. <constant>RENDER_BOOKMARK</constant> denote standard HTML link types.
  914. <constant>RENDER_CUSTOM</constant> denotes non-standard relations that
  915. specified in pages. <constant>RENDER_ALL</constant> denotes standard and
  916. non-standard relations.
  917. </para>
  918. <para>
  919. Methods in the links helper:
  920. </para>
  921. <itemizedlist>
  922. <listitem>
  923. <para>
  924. <code>{get|set}RenderFlag()</code> gets/sets the render
  925. flag. Default is <constant>RENDER_ALL</constant>. See examples
  926. below on how to set the render flag.
  927. </para>
  928. </listitem>
  929. <listitem>
  930. <para>
  931. <methodname>findAllRelations()</methodname> finds all relations of
  932. all types for a given page.
  933. </para>
  934. </listitem>
  935. <listitem>
  936. <para>
  937. <methodname>findRelation()</methodname> finds all relations of a given
  938. type from a given page.
  939. </para>
  940. </listitem>
  941. <listitem>
  942. <para>
  943. <code>searchRel{Start|Next|Prev|Chapter|Section|Subsection}()</code>
  944. traverses a container to find forward relations to
  945. the start page, the next page, the previous page,
  946. chapters, sections, and subsections.
  947. </para>
  948. </listitem>
  949. <listitem>
  950. <para>
  951. <code>searchRev{Section|Subsection}()</code> traverses
  952. a container to find reverse relations to sections or
  953. subsections.
  954. </para>
  955. </listitem>
  956. <listitem>
  957. <para>
  958. <methodname>renderLink()</methodname> renders a single <code>link</code>
  959. element.
  960. </para>
  961. </listitem>
  962. </itemizedlist>
  963. <example id="zend.view.helpers.initial.navigation.links.example1">
  964. <title>Specify relations in pages</title>
  965. <para>
  966. This example shows how to specify relations in pages.
  967. </para>
  968. <programlisting language="php"><![CDATA[
  969. $container = new Zend_Navigation(array(
  970. array(
  971. 'label' => 'Relations using strings',
  972. 'rel' => array(
  973. 'alternate' => 'http://www.example.org/'
  974. ),
  975. 'rev' => array(
  976. 'alternate' => 'http://www.example.net/'
  977. )
  978. ),
  979. array(
  980. 'label' => 'Relations using arrays',
  981. 'rel' => array(
  982. 'alternate' => array(
  983. 'label' => 'Example.org',
  984. 'uri' => 'http://www.example.org/'
  985. )
  986. )
  987. ),
  988. array(
  989. 'label' => 'Relations using configs',
  990. 'rel' => array(
  991. 'alternate' => new Zend_Config(array(
  992. 'label' => 'Example.org',
  993. 'uri' => 'http://www.example.org/'
  994. ))
  995. )
  996. ),
  997. array(
  998. 'label' => 'Relations using pages instance',
  999. 'rel' => array(
  1000. 'alternate' => Zend_Navigation_Page::factory(array(
  1001. 'label' => 'Example.org',
  1002. 'uri' => 'http://www.example.org/'
  1003. ))
  1004. )
  1005. )
  1006. ));
  1007. ]]></programlisting>
  1008. </example>
  1009. <example id="zend.view.helpers.initial.navigation.links.example2">
  1010. <title>Default rendering of links</title>
  1011. <para>
  1012. This example shows how to render a menu from a container
  1013. registered/found in the view helper.
  1014. </para>
  1015. <programlisting language="php"><![CDATA[
  1016. In a view script or layout:
  1017. <?php echo $this->view->navigation()->links(); ?>
  1018. Output:
  1019. <link rel="alternate" href="/products/server/faq/format/xml">
  1020. <link rel="start" href="/" title="Home">
  1021. <link rel="next" href="/products/server/editions" title="Editions">
  1022. <link rel="prev" href="/products/server" title="Foo Server">
  1023. <link rel="chapter" href="/products" title="Products">
  1024. <link rel="chapter" href="/company/about" title="Company">
  1025. <link rel="chapter" href="/community" title="Community">
  1026. <link rel="canonical" href="http://www.example.com/?page=server-faq">
  1027. <link rev="subsection" href="/products/server" title="Foo Server">
  1028. ]]></programlisting>
  1029. </example>
  1030. <example id="zend.view.helpers.initial.navigation.links.example3">
  1031. <title>Specify which relations to render</title>
  1032. <para>
  1033. This example shows how to specify which relations to find
  1034. and render.
  1035. </para>
  1036. <programlisting language="php"><![CDATA[
  1037. Render only start, next, and prev:
  1038. $helper->setRenderFlag(Zend_View_Helper_Navigation_Links::RENDER_START |
  1039. Zend_View_Helper_Navigation_Links::RENDER_NEXT |
  1040. Zend_View_Helper_Navigation_Links::RENDER_PREV);
  1041. Output:
  1042. <link rel="start" href="/" title="Home">
  1043. <link rel="next" href="/products/server/editions" title="Editions">
  1044. <link rel="prev" href="/products/server" title="Foo Server">
  1045. ]]></programlisting>
  1046. <programlisting language="php"><![CDATA[
  1047. Render only native link types:
  1048. $helper->setRenderFlag(Zend_View_Helper_Navigation_Links::RENDER_ALL ^
  1049. Zend_View_Helper_Navigation_Links::RENDER_CUSTOM);
  1050. Output:
  1051. <link rel="alternate" href="/products/server/faq/format/xml">
  1052. <link rel="start" href="/" title="Home">
  1053. <link rel="next" href="/products/server/editions" title="Editions">
  1054. <link rel="prev" href="/products/server" title="Foo Server">
  1055. <link rel="chapter" href="/products" title="Products">
  1056. <link rel="chapter" href="/company/about" title="Company">
  1057. <link rel="chapter" href="/community" title="Community">
  1058. <link rev="subsection" href="/products/server" title="Foo Server">
  1059. ]]></programlisting>
  1060. <programlisting language="php"><![CDATA[
  1061. Render all but chapter:
  1062. $helper->setRenderFlag(Zend_View_Helper_Navigation_Links::RENDER_ALL ^
  1063. Zend_View_Helper_Navigation_Links::RENDER_CHAPTER);
  1064. Output:
  1065. <link rel="alternate" href="/products/server/faq/format/xml">
  1066. <link rel="start" href="/" title="Home">
  1067. <link rel="next" href="/products/server/editions" title="Editions">
  1068. <link rel="prev" href="/products/server" title="Foo Server">
  1069. <link rel="canonical" href="http://www.example.com/?page=server-faq">
  1070. <link rev="subsection" href="/products/server" title="Foo Server">
  1071. ]]></programlisting>
  1072. </example>
  1073. </sect4>
  1074. <sect4 id="zend.view.helpers.initial.navigation.menu">
  1075. <title>Menu Helper</title>
  1076. <para>
  1077. The Menu helper is used for rendering menus from navigation
  1078. containers. By default, the menu will be rendered using
  1079. HTML <code>UL</code> and <code>LI</code> tags, but the helper also
  1080. allows using a partial view script.
  1081. </para>
  1082. <para>
  1083. Methods in the Menu helper:
  1084. </para>
  1085. <itemizedlist>
  1086. <listitem>
  1087. <para>
  1088. <code>{get|set}UlClass()</code> gets/sets the <acronym>CSS</acronym> class
  1089. used in <methodname>renderMenu()</methodname>.
  1090. </para>
  1091. </listitem>
  1092. <listitem>
  1093. <para>
  1094. <code>{get|set}OnlyActiveBranch()</code> gets/sets a flag
  1095. specifying whether only the active branch of a container
  1096. should be rendered.
  1097. </para>
  1098. </listitem>
  1099. <listitem>
  1100. <para>
  1101. <code>{get|set}RenderParents()</code> gets/sets a flag
  1102. specifying whether parents should be rendered when only
  1103. rendering active branch of a container. If set to
  1104. <constant>FALSE</constant>, only the deepest active menu will be
  1105. rendered.
  1106. </para>
  1107. </listitem>
  1108. <listitem>
  1109. <para>
  1110. <code>{get|set}Partial()</code> gets/sets a partial view
  1111. script that should be used for rendering menu.
  1112. If a partial view script is set, the helper's
  1113. <methodname>render()</methodname> method will use the
  1114. <methodname>renderPartial()</methodname> method. If no partial is
  1115. set, the <methodname>renderMenu()</methodname> method is used.
  1116. The helper expects the partial to be a <type>String</type>
  1117. or an <type>Array</type> with two elements. If the partial
  1118. is a <type>String</type>, it denotes the name of the partial
  1119. script to use. If it is an <type>Array</type>, the first
  1120. element will be used as the name of the partial view
  1121. script, and the second element is the module where the
  1122. script is found.
  1123. </para>
  1124. </listitem>
  1125. <listitem>
  1126. <para>
  1127. <methodname>htmlify()</methodname> overrides the method from the
  1128. abstract class to return <code>span</code> elements
  1129. if the page has no <code>href</code>.
  1130. </para>
  1131. </listitem>
  1132. <listitem>
  1133. <para>
  1134. <methodname>renderMenu($container = null, $options = array())</methodname>
  1135. is the default render method, and will render a container as
  1136. a HTML <code>UL</code> list.
  1137. </para>
  1138. <para>
  1139. If <varname>$container</varname> is not given, the container
  1140. registered in the helper will be rendered.
  1141. </para>
  1142. <para>
  1143. <varname>$options</varname> is used for overriding options
  1144. specified temporarily without rsetting the values in the
  1145. helper instance. It is an associative array where each key
  1146. corresponds to an option in the helper.
  1147. </para>
  1148. <para>
  1149. Recognized options:
  1150. </para>
  1151. <itemizedlist>
  1152. <listitem>
  1153. <para>
  1154. <code>indent</code>; indentation. Expects a
  1155. <type>String</type> or an <code>int</code>
  1156. value.
  1157. </para>
  1158. </listitem>
  1159. <listitem>
  1160. <para>
  1161. <code>minDepth</code>; minimum depth. Expcects
  1162. an <code>int</code> or <constant>NULL</constant> (no
  1163. minimum depth).
  1164. </para>
  1165. </listitem>
  1166. <listitem>
  1167. <para>
  1168. <code>maxDepth</code>; maximum depth. Expcects
  1169. an <code>int</code> or <constant>NULL</constant> (no
  1170. maximum depth).
  1171. </para>
  1172. </listitem>
  1173. <listitem>
  1174. <para>
  1175. <code>ulClass</code>; <acronym>CSS</acronym> class for
  1176. <code>ul</code> element. Expects a
  1177. <type>String</type>.
  1178. </para>
  1179. </listitem>
  1180. <listitem>
  1181. <para>
  1182. <code>onlyActiveBranch</code>; whether only
  1183. active branch should be rendered. Expects
  1184. a <type>Boolean</type> value.
  1185. </para>
  1186. </listitem>
  1187. <listitem>
  1188. <para>
  1189. <code>renderParents</code>; whether parents
  1190. should be rendered if only rendering active
  1191. branch. Expects a <type>Boolean</type> value.
  1192. </para>
  1193. </listitem>
  1194. </itemizedlist>
  1195. <para>
  1196. If an option is not given, the value set in the helper
  1197. will be used.
  1198. </para>
  1199. </listitem>
  1200. <listitem>
  1201. <para>
  1202. <methodname>renderPartial()</methodname> is used for rendering the menu
  1203. using a partial view script.
  1204. </para>
  1205. </listitem>
  1206. <listitem>
  1207. <para>
  1208. <methodname>renderSubMenu()</methodname> renders the deepest menu level
  1209. of a container's active branch.
  1210. </para>
  1211. </listitem>
  1212. </itemizedlist>
  1213. <example id="zend.view.helpers.initial.navigation.menu.example1">
  1214. <title>Rendering a menu</title>
  1215. <para>
  1216. This example shows how to render a menu from a container
  1217. registered/found in the view helper. Notice how pages
  1218. are filtered out based on visibility and <acronym>ACL</acronym>.
  1219. </para>
  1220. <programlisting language="php"><![CDATA[
  1221. In a view script or layout:
  1222. <?php echo $this->navigation()->menu()->render() ?>
  1223. Or simply:
  1224. <?php echo $this->navigation()->menu() ?>
  1225. Or if short tags are enabled:
  1226. <?= $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> format</ulink>.
  1627. Read more about <ulink url="http://en.wikipedia.org/wiki/Sitemaps">Sitemaps
  1628. 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 <acronym>URL</acronym> will
  1664. 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 specified,
  1776. it will be determined by the helper.
  1777. </para>
  1778. </listitem>
  1779. <listitem>
  1780. <para>
  1781. <methodname>url()</methodname> is used to generate absolute <acronym>URL</acronym>s to
  1782. 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. </sect4>
  1981. <sect4 id="zend.view.helpers.initial.navigation.navigation">
  1982. <title>Navigation Helper</title>
  1983. <para>
  1984. The Navigation helper is a proxy helper
  1985. that relays calls to other navigational helpers. It can be
  1986. considered an entry point to all navigation-related view tasks.
  1987. The aforementioned navigational helpers are in the namespace
  1988. <classname>Zend_View_Helper_Navigation</classname>, and would thus require
  1989. the path <code>Zend/View/Helper/Navigation</code> to be added as
  1990. a helper path to the view. With the proxy helper residing in the
  1991. <classname>Zend_View_Helper</classname> namespace, it will always be
  1992. available, without the need to add any helper paths to the view.
  1993. </para>
  1994. <para>
  1995. The Navigation helper finds other helpers that implement the
  1996. <classname>Zend_View_Helper_Navigation_Helper</classname>
  1997. interface, which means custom view helpers can also be proxied.
  1998. This would, however, require that the custom helper path is added
  1999. to the view.
  2000. </para>
  2001. <para>
  2002. When proxying to other helpers, the Navigation helper can inject
  2003. its container, <acronym>ACL</acronym>/role, and translator. This means that you
  2004. won't have to explicitly set all three in all navigational
  2005. helpers, nor resort to injecting by means of
  2006. <classname>Zend_Registry</classname> or static methods.
  2007. </para>
  2008. <itemizedlist>
  2009. <listitem>
  2010. <para>
  2011. <methodname>findHelper()</methodname> finds the given helper,
  2012. verifies that it is a navigational helper, and injects
  2013. container, <acronym>ACL</acronym>/role and translator.
  2014. </para>
  2015. </listitem>
  2016. <listitem>
  2017. <para>
  2018. <code>{get|set}InjectContainer()</code> gets/sets a flag
  2019. indicating whether the container should be injected to
  2020. proxied helpers. Default is <constant>TRUE</constant>.
  2021. </para>
  2022. </listitem>
  2023. <listitem>
  2024. <para>
  2025. <code>{get|set}InjectAcl()</code> gets/sets a flag
  2026. indicating whether the <acronym>ACL</acronym>/role should be injected to
  2027. proxied helpers. Default is <constant>TRUE</constant>.
  2028. </para>
  2029. </listitem>
  2030. <listitem>
  2031. <para>
  2032. <code>{get|set}InjectTranslator()</code> gets/sets a flag
  2033. indicating whether the translator should be injected to
  2034. proxied helpers. Default is <constant>TRUE</constant>.
  2035. </para>
  2036. </listitem>
  2037. <listitem>
  2038. <para>
  2039. <code>{get|set}DefaultProxy()</code> gets/sets the default
  2040. proxy. Default is <code>'menu'</code>.
  2041. </para>
  2042. </listitem>
  2043. <listitem>
  2044. <para>
  2045. <methodname>render()</methodname> proxies to the render method of
  2046. the default proxy.
  2047. </para>
  2048. </listitem>
  2049. </itemizedlist>
  2050. </sect4>
  2051. </sect3>