Zend_View-Helpers-Navigation.xml 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221
  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. The two calls above take advantage of the magic __toString() method,
  596. and are equivalent to:
  597. <?php echo $this->navigation()->breadcrumbs()->render(); ?>
  598. Output:
  599. <a href="/products">Products</a> &gt; <a href="/products/server">Foo Server</a> &gt; FAQ
  600. ]]></programlisting>
  601. </example>
  602. <example id="zend.view.helpers.initial.navigation.breadcrumbs.example2">
  603. <title>Specifying indentation</title>
  604. <para>
  605. This example shows how to render breadcrumbs with initial
  606. indentation.
  607. </para>
  608. <programlisting language="php"><![CDATA[
  609. Rendering with 8 spaces indentation:
  610. <?php echo $this->navigation()->breadcrumbs()->setIndent(8);?>
  611. Output:
  612. <a href="/products">Products</a> &gt; <a href="/products/server">Foo Server</a> &gt; FAQ
  613. ]]></programlisting>
  614. </example>
  615. <example id="zend.view.helpers.initial.navigation.breadcrumbs.example3">
  616. <title>Customize breadcrumbs output</title>
  617. <para>
  618. This example shows how to customze breadcrumbs output by
  619. specifying various options.
  620. </para>
  621. <programlisting language="php"><![CDATA[
  622. In a view script or layout:
  623. <?php
  624. echo $this->navigation()
  625. ->breadcrumbs()
  626. ->setLinkLast(true) // link last page
  627. ->setMaxDepth(1) // stop at level 1
  628. ->setSeparator(' &#9654;' . PHP_EOL); // cool separator with newline
  629. ?>
  630. Output:
  631. <a href="/products">Products</a> &#9654;
  632. <a href="/products/server">Foo Server</a>
  633. /////////////////////////////////////////////////////
  634. Setting minimum depth required to render breadcrumbs:
  635. <?php
  636. $this->navigation()->breadcrumbs()->setMinDepth(10);
  637. echo $this->navigation()->breadcrumbs();
  638. ?>
  639. Output:
  640. Nothing, because the deepest active page is not at level 10 or deeper.
  641. ]]></programlisting>
  642. </example>
  643. <example id="zend.view.helpers.initial.navigation.breadcrumbs.example4">
  644. <title>Rendering breadcrumbs using a partial view script</title>
  645. <para>
  646. This example shows how to render customized breadcrumbs using
  647. a partial vew script. By calling <methodname>setPartial()</methodname>,
  648. you can specify a partial view script that will be used
  649. when calling <methodname>render()</methodname>. When a partial is specified,
  650. the <methodname>renderPartial()</methodname> method will be called. This
  651. method will find the deepest active page and pass an array
  652. of pages that leads to the active page to the partial view
  653. script.
  654. </para>
  655. <para>
  656. In a layout:
  657. </para>
  658. <programlisting language="php"><![CDATA[
  659. $partial = ;
  660. echo $this->navigation()->breadcrumbs()
  661. ->setPartial(array('breadcrumbs.phtml', 'default'));
  662. ]]></programlisting>
  663. <para>
  664. Contents of
  665. <code>application/modules/default/views/breadcrumbs.phtml</code>:
  666. </para>
  667. <programlisting language="php"><![CDATA[
  668. echo implode(', ', array_map(
  669. create_function('$a', 'return $a->getLabel();'),
  670. $this->pages));
  671. ]]></programlisting>
  672. <para>
  673. Output:
  674. </para>
  675. <programlisting language="php"><![CDATA[
  676. Products, Foo Server, FAQ
  677. ]]></programlisting>
  678. </example>
  679. </sect4>
  680. <sect4 id="zend.view.helpers.initial.navigation.links">
  681. <title>Links Helper</title>
  682. <para>
  683. The links helper is used for rendering HTML <constant>LINK</constant>
  684. elements. Links are used for describing document relationships
  685. of the currently active page. Read more about links and link
  686. types at <ulink url="http://www.w3.org/TR/html4/struct/links.html#h-12.3">Document
  687. relationships: the LINK element (HTML4 W3C Rec.)</ulink>
  688. and <ulink
  689. url="http://www.w3.org/TR/html4/types.html#h-6.12">Link types (HTML4 W3C
  690. Rec.)</ulink> in the HTML4 W3C Recommendation.
  691. </para>
  692. <para>
  693. There are two types of relations; forward and reverse, indicated
  694. by the keyords <code>'rel'</code> and <code>'rev'</code>. Most
  695. methods in the helper will take a <varname>$rel</varname> param, which
  696. must be either <code>'rel'</code> or <code>'rev'</code>. Most
  697. methods also take a <varname>$type</varname> param, which is used
  698. for specifying the link type (e.g. alternate, start, next, prev,
  699. chapter, etc).
  700. </para>
  701. <para>
  702. Relationships can be added to page objects manually, or found
  703. by traversing the container registered in the helper. The method
  704. <methodname>findRelation($page, $rel, $type)</methodname> will first try
  705. to find the given <varname>$rel</varname> of <varname>$type</varname> from
  706. the <varname>$page</varname> by calling <code>$page->findRel($type)</code>
  707. or <code>$page->findRel($type)</code>. If the <varname>$page</varname>
  708. has a relation that can be converted to a page instance, that
  709. relation will be used. If the <varname>$page</varname> instance doesn't
  710. have the specified <varname>$type</varname>, the helper will look for
  711. a method in the helper named <code>search$rel$type</code> (e.g.
  712. <methodname>searchRelNext()</methodname> or
  713. <methodname>searchRevAlternate()</methodname>).
  714. If such a method exists, it will be used for determining the
  715. <varname>$page</varname>'s relation by traversing the container.
  716. </para>
  717. <para>
  718. Not all relations can be determined by traversing the container.
  719. These are the relations that will be found by searching:
  720. </para>
  721. <itemizedlist>
  722. <listitem>
  723. <para>
  724. <methodname>searchRelStart()</methodname>, forward 'start'
  725. relation: the first page in the container.
  726. </para>
  727. </listitem>
  728. <listitem>
  729. <para>
  730. <methodname>searchRelNext()</methodname>, forward 'next'
  731. relation; finds the next page in the container, i.e.
  732. the page after the active page.
  733. </para>
  734. </listitem>
  735. <listitem>
  736. <para>
  737. <methodname>searchRelPrev()</methodname>, forward 'prev'
  738. relation; finds the previous page, i.e. the page before
  739. the active page.
  740. </para>
  741. </listitem>
  742. <listitem>
  743. <para>
  744. <methodname>searchRelChapter()</methodname>, forward 'chapter'
  745. relations; finds all pages on level 0 except the 'start'
  746. relation or the active page if it's on level 0.
  747. </para>
  748. </listitem>
  749. <listitem>
  750. <para>
  751. <methodname>searchRelSection()</methodname>, forward 'section'
  752. relations; finds all child pages of the active page if
  753. the active page is on level 0 (a 'chapter').
  754. </para>
  755. </listitem>
  756. <listitem>
  757. <para>
  758. <methodname>searchRelSubsection()</methodname>, forward 'subsection'
  759. relations; finds all child pages of the active page if
  760. the active pages is on level 1 (a 'section').
  761. </para>
  762. </listitem>
  763. <listitem>
  764. <para>
  765. <methodname>searchRevSection()</methodname>, reverse 'section'
  766. relation; finds the parent of the active page if the
  767. active page is on level 1 (a 'section').
  768. </para>
  769. </listitem>
  770. <listitem>
  771. <para>
  772. <methodname>searchRevSubsection()</methodname>, reverse 'subsection'
  773. relation; finds the parent of the active page if the
  774. active page is on level 2 (a 'subsection').
  775. </para>
  776. </listitem>
  777. </itemizedlist>
  778. <note>
  779. <para>
  780. When looking for relations in the page instance
  781. (<code>$page->getRel($type)</code> or
  782. <code>$page->getRev($type)</code>), the helper accepts the
  783. values of type <type>String</type>, <type>Array</type>,
  784. <classname>Zend_Config</classname>, or
  785. <classname>Zend_Navigation_Page</classname>. If a string
  786. is found, it will be converted to a
  787. <classname>Zend_Navigation_Page_Uri</classname>. If an array
  788. or a config is found, it will be converted to one or several
  789. page instances. If the first key of the array/config is numeric,
  790. it will be considered to contain several pages, and each
  791. element will be passed to the
  792. <link linkend="zend.navigation.pages.factory">page factory</link>.
  793. If the first key is not numeric, the array/config will be
  794. passed to the page factory directly, and a single page will
  795. be returned.
  796. </para>
  797. </note>
  798. <para>
  799. The helper also supports magic methods for finding relations.
  800. E.g. to find forward alternate relations, call
  801. <code>$helper->findRelAlternate($page)</code>, and to find
  802. reverse section relations, call
  803. <code>$helper->findRevSection($page)</code>. Those calls correspond
  804. to <code>$helper->findRelation($page, 'rel', 'alternate');</code>
  805. and <code>$helper->findRelation($page, 'rev', 'section');</code>
  806. respectively.
  807. </para>
  808. <para>
  809. To customize which relations should be rendered, the helper
  810. uses a render flag. The render flag is an integer value, and will be
  811. used in a
  812. <ulink url="http://php.net/manual/en/language.operators.bitwise.php">bitwse
  813. <code>and</code> (<code>&amp;</code>) operation</ulink> against the
  814. helper's render constants to determine if the relation that belongs
  815. to the render constant should be rendered.
  816. </para>
  817. <para>
  818. See the
  819. <link linkend="zend.view.helpers.initial.navigation.links.example3">example
  820. below</link> for more information.
  821. </para>
  822. <itemizedlist>
  823. <listitem>
  824. <para>
  825. <constant>Zend_View_Helper_Navigation_Link::RENDER_ALTERNATE</constant>
  826. </para>
  827. </listitem>
  828. <listitem>
  829. <para>
  830. <constant>Zend_View_Helper_Navigation_Link::RENDER_STYLESHEET</constant>
  831. </para>
  832. </listitem>
  833. <listitem>
  834. <para>
  835. <constant>Zend_View_Helper_Navigation_Link::RENDER_START</constant>
  836. </para>
  837. </listitem>
  838. <listitem>
  839. <para>
  840. <constant>Zend_View_Helper_Navigation_Link::RENDER_NEXT</constant>
  841. </para>
  842. </listitem>
  843. <listitem>
  844. <para>
  845. <constant>Zend_View_Helper_Navigation_Link::RENDER_PREV</constant>
  846. </para>
  847. </listitem>
  848. <listitem>
  849. <para>
  850. <constant>Zend_View_Helper_Navigation_Link::RENDER_CONTENTS</constant>
  851. </para>
  852. </listitem>
  853. <listitem>
  854. <para>
  855. <constant>Zend_View_Helper_Navigation_Link::RENDER_INDEX</constant>
  856. </para>
  857. </listitem>
  858. <listitem>
  859. <para>
  860. <constant>Zend_View_Helper_Navigation_Link::RENDER_GLOSSARY</constant>
  861. </para>
  862. </listitem>
  863. <listitem>
  864. <para>
  865. <constant>Zend_View_Helper_Navigation_Link::RENDER_COPYRIGHT</constant>
  866. </para>
  867. </listitem>
  868. <listitem>
  869. <para>
  870. <constant>Zend_View_Helper_Navigation_Link::RENDER_CHAPTER</constant>
  871. </para>
  872. </listitem>
  873. <listitem>
  874. <para>
  875. <constant>Zend_View_Helper_Navigation_Link::RENDER_SECTION</constant>
  876. </para>
  877. </listitem>
  878. <listitem>
  879. <para>
  880. <constant>Zend_View_Helper_Navigation_Link::RENDER_SUBSECTION</constant>
  881. </para>
  882. </listitem>
  883. <listitem>
  884. <para>
  885. <constant>Zend_View_Helper_Navigation_Link::RENDER_APPENDIX</constant>
  886. </para>
  887. </listitem>
  888. <listitem>
  889. <para>
  890. <constant>Zend_View_Helper_Navigation_Link::RENDER_HELP</constant>
  891. </para>
  892. </listitem>
  893. <listitem>
  894. <para>
  895. <constant>Zend_View_Helper_Navigation_Link::RENDER_BOOKMARK</constant>
  896. </para>
  897. </listitem>
  898. <listitem>
  899. <para>
  900. <constant>Zend_View_Helper_Navigation_Link::RENDER_CUSTOM</constant>
  901. </para>
  902. </listitem>
  903. <listitem>
  904. <para>
  905. <constant>Zend_View_Helper_Navigation_Link::RENDER_ALL</constant>
  906. </para>
  907. </listitem>
  908. </itemizedlist>
  909. <para>
  910. The constants from <constant>RENDER_ALTERNATE</constant> to
  911. <constant>RENDER_BOOKMARK</constant> denote standard HTML link types.
  912. <constant>RENDER_CUSTOM</constant> denotes non-standard relations that
  913. specified in pages. <constant>RENDER_ALL</constant> denotes standard and
  914. non-standard relations.
  915. </para>
  916. <para>
  917. Methods in the links helper:
  918. </para>
  919. <itemizedlist>
  920. <listitem>
  921. <para>
  922. <code>{get|set}RenderFlag()</code> gets/sets the render
  923. flag. Default is <constant>RENDER_ALL</constant>. See examples
  924. below on how to set the render flag.
  925. </para>
  926. </listitem>
  927. <listitem>
  928. <para>
  929. <methodname>findAllRelations()</methodname> finds all relations of
  930. all types for a given page.
  931. </para>
  932. </listitem>
  933. <listitem>
  934. <para>
  935. <methodname>findRelation()</methodname> finds all relations of a given
  936. type from a given page.
  937. </para>
  938. </listitem>
  939. <listitem>
  940. <para>
  941. <code>searchRel{Start|Next|Prev|Chapter|Section|Subsection}()</code>
  942. traverses a container to find forward relations to
  943. the start page, the next page, the previous page,
  944. chapters, sections, and subsections.
  945. </para>
  946. </listitem>
  947. <listitem>
  948. <para>
  949. <code>searchRev{Section|Subsection}()</code> traverses
  950. a container to find reverse relations to sections or
  951. subsections.
  952. </para>
  953. </listitem>
  954. <listitem>
  955. <para>
  956. <methodname>renderLink()</methodname> renders a single <code>link</code>
  957. element.
  958. </para>
  959. </listitem>
  960. </itemizedlist>
  961. <example id="zend.view.helpers.initial.navigation.links.example1">
  962. <title>Specify relations in pages</title>
  963. <para>
  964. This example shows how to specify relations in pages.
  965. </para>
  966. <programlisting language="php"><![CDATA[
  967. $container = new Zend_Navigation(array(
  968. array(
  969. 'label' => 'Relations using strings',
  970. 'rel' => array(
  971. 'alternate' => 'http://www.example.org/'
  972. ),
  973. 'rev' => array(
  974. 'alternate' => 'http://www.example.net/'
  975. )
  976. ),
  977. array(
  978. 'label' => 'Relations using arrays',
  979. 'rel' => array(
  980. 'alternate' => array(
  981. 'label' => 'Example.org',
  982. 'uri' => 'http://www.example.org/'
  983. )
  984. )
  985. ),
  986. array(
  987. 'label' => 'Relations using configs',
  988. 'rel' => array(
  989. 'alternate' => new Zend_Config(array(
  990. 'label' => 'Example.org',
  991. 'uri' => 'http://www.example.org/'
  992. ))
  993. )
  994. ),
  995. array(
  996. 'label' => 'Relations using pages instance',
  997. 'rel' => array(
  998. 'alternate' => Zend_Navigation_Page::factory(array(
  999. 'label' => 'Example.org',
  1000. 'uri' => 'http://www.example.org/'
  1001. ))
  1002. )
  1003. )
  1004. ));
  1005. ]]></programlisting>
  1006. </example>
  1007. <example id="zend.view.helpers.initial.navigation.links.example2">
  1008. <title>Default rendering of links</title>
  1009. <para>
  1010. This example shows how to render a menu from a container
  1011. registered/found in the view helper.
  1012. </para>
  1013. <programlisting language="php"><![CDATA[
  1014. In a view script or layout:
  1015. <?php echo $this->view->navigation()->links(); ?>
  1016. Output:
  1017. <link rel="alternate" href="/products/server/faq/format/xml">
  1018. <link rel="start" href="/" title="Home">
  1019. <link rel="next" href="/products/server/editions" title="Editions">
  1020. <link rel="prev" href="/products/server" title="Foo Server">
  1021. <link rel="chapter" href="/products" title="Products">
  1022. <link rel="chapter" href="/company/about" title="Company">
  1023. <link rel="chapter" href="/community" title="Community">
  1024. <link rel="canonical" href="http://www.example.com/?page=server-faq">
  1025. <link rev="subsection" href="/products/server" title="Foo Server">
  1026. ]]></programlisting>
  1027. </example>
  1028. <example id="zend.view.helpers.initial.navigation.links.example3">
  1029. <title>Specify which relations to render</title>
  1030. <para>
  1031. This example shows how to specify which relations to find
  1032. and render.
  1033. </para>
  1034. <programlisting language="php"><![CDATA[
  1035. Render only start, next, and prev:
  1036. $helper->setRenderFlag(Zend_View_Helper_Navigation_Links::RENDER_START |
  1037. Zend_View_Helper_Navigation_Links::RENDER_NEXT |
  1038. Zend_View_Helper_Navigation_Links::RENDER_PREV);
  1039. Output:
  1040. <link rel="start" href="/" title="Home">
  1041. <link rel="next" href="/products/server/editions" title="Editions">
  1042. <link rel="prev" href="/products/server" title="Foo Server">
  1043. ]]></programlisting>
  1044. <programlisting language="php"><![CDATA[
  1045. Render only native link types:
  1046. $helper->setRenderFlag(Zend_View_Helper_Navigation_Links::RENDER_ALL ^
  1047. Zend_View_Helper_Navigation_Links::RENDER_CUSTOM);
  1048. Output:
  1049. <link rel="alternate" href="/products/server/faq/format/xml">
  1050. <link rel="start" href="/" title="Home">
  1051. <link rel="next" href="/products/server/editions" title="Editions">
  1052. <link rel="prev" href="/products/server" title="Foo Server">
  1053. <link rel="chapter" href="/products" title="Products">
  1054. <link rel="chapter" href="/company/about" title="Company">
  1055. <link rel="chapter" href="/community" title="Community">
  1056. <link rev="subsection" href="/products/server" title="Foo Server">
  1057. ]]></programlisting>
  1058. <programlisting language="php"><![CDATA[
  1059. Render all but chapter:
  1060. $helper->setRenderFlag(Zend_View_Helper_Navigation_Links::RENDER_ALL ^
  1061. Zend_View_Helper_Navigation_Links::RENDER_CHAPTER);
  1062. Output:
  1063. <link rel="alternate" href="/products/server/faq/format/xml">
  1064. <link rel="start" href="/" title="Home">
  1065. <link rel="next" href="/products/server/editions" title="Editions">
  1066. <link rel="prev" href="/products/server" title="Foo Server">
  1067. <link rel="canonical" href="http://www.example.com/?page=server-faq">
  1068. <link rev="subsection" href="/products/server" title="Foo Server">
  1069. ]]></programlisting>
  1070. </example>
  1071. </sect4>
  1072. <sect4 id="zend.view.helpers.initial.navigation.menu">
  1073. <title>Menu Helper</title>
  1074. <para>
  1075. The Menu helper is used for rendering menus from navigation
  1076. containers. By default, the menu will be rendered using
  1077. HTML <code>UL</code> and <code>LI</code> tags, but the helper also
  1078. allows using a partial view script.
  1079. </para>
  1080. <para>
  1081. Methods in the Menu helper:
  1082. </para>
  1083. <itemizedlist>
  1084. <listitem>
  1085. <para>
  1086. <code>{get|set}UlClass()</code> gets/sets the <acronym>CSS</acronym> class
  1087. used in <methodname>renderMenu()</methodname>.
  1088. </para>
  1089. </listitem>
  1090. <listitem>
  1091. <para>
  1092. <code>{get|set}OnlyActiveBranch()</code> gets/sets a flag
  1093. specifying whether only the active branch of a container
  1094. should be rendered.
  1095. </para>
  1096. </listitem>
  1097. <listitem>
  1098. <para>
  1099. <code>{get|set}RenderParents()</code> gets/sets a flag
  1100. specifying whether parents should be rendered when only
  1101. rendering active branch of a container. If set to
  1102. <constant>FALSE</constant>, only the deepest active menu will be
  1103. rendered.
  1104. </para>
  1105. </listitem>
  1106. <listitem>
  1107. <para>
  1108. <code>{get|set}Partial()</code> gets/sets a partial view
  1109. script that should be used for rendering menu.
  1110. If a partial view script is set, the helper's
  1111. <methodname>render()</methodname> method will use the
  1112. <methodname>renderPartial()</methodname> method. If no partial is
  1113. set, the <methodname>renderMenu()</methodname> method is used.
  1114. The helper expects the partial to be a <type>String</type>
  1115. or an <type>Array</type> with two elements. If the partial
  1116. is a <type>String</type>, it denotes the name of the partial
  1117. script to use. If it is an <type>Array</type>, the first
  1118. element will be used as the name of the partial view
  1119. script, and the second element is the module where the
  1120. script is found.
  1121. </para>
  1122. </listitem>
  1123. <listitem>
  1124. <para>
  1125. <methodname>htmlify()</methodname> overrides the method from the
  1126. abstract class to return <code>span</code> elements
  1127. if the page has no <code>href</code>.
  1128. </para>
  1129. </listitem>
  1130. <listitem>
  1131. <para>
  1132. <methodname>renderMenu($container = null, $options = array())</methodname>
  1133. is the default render method, and will render a container as
  1134. a HTML <code>UL</code> list.
  1135. </para>
  1136. <para>
  1137. If <varname>$container</varname> is not given, the container
  1138. registered in the helper will be rendered.
  1139. </para>
  1140. <para>
  1141. <varname>$options</varname> is used for overriding options
  1142. specified temporarily without rsetting the values in the
  1143. helper instance. It is an associative array where each key
  1144. corresponds to an option in the helper.
  1145. </para>
  1146. <para>
  1147. Recognized options:
  1148. </para>
  1149. <itemizedlist>
  1150. <listitem>
  1151. <para>
  1152. <code>indent</code>; indentation. Expects a
  1153. <type>String</type> or an <code>int</code>
  1154. value.
  1155. </para>
  1156. </listitem>
  1157. <listitem>
  1158. <para>
  1159. <code>minDepth</code>; minimum depth. Expcects
  1160. an <code>int</code> or <constant>NULL</constant> (no
  1161. minimum depth).
  1162. </para>
  1163. </listitem>
  1164. <listitem>
  1165. <para>
  1166. <code>maxDepth</code>; maximum depth. Expcects
  1167. an <code>int</code> or <constant>NULL</constant> (no
  1168. maximum depth).
  1169. </para>
  1170. </listitem>
  1171. <listitem>
  1172. <para>
  1173. <code>ulClass</code>; <acronym>CSS</acronym> class for
  1174. <code>ul</code> element. Expects a
  1175. <type>String</type>.
  1176. </para>
  1177. </listitem>
  1178. <listitem>
  1179. <para>
  1180. <code>onlyActiveBranch</code>; whether only
  1181. active branch should be rendered. Expects
  1182. a <type>Boolean</type> value.
  1183. </para>
  1184. </listitem>
  1185. <listitem>
  1186. <para>
  1187. <code>renderParents</code>; whether parents
  1188. should be rendered if only rendering active
  1189. branch. Expects a <type>Boolean</type> value.
  1190. </para>
  1191. </listitem>
  1192. </itemizedlist>
  1193. <para>
  1194. If an option is not given, the value set in the helper
  1195. will be used.
  1196. </para>
  1197. </listitem>
  1198. <listitem>
  1199. <para>
  1200. <methodname>renderPartial()</methodname> is used for rendering the menu
  1201. using a partial view script.
  1202. </para>
  1203. </listitem>
  1204. <listitem>
  1205. <para>
  1206. <methodname>renderSubMenu()</methodname> renders the deepest menu level
  1207. of a container's active branch.
  1208. </para>
  1209. </listitem>
  1210. </itemizedlist>
  1211. <example id="zend.view.helpers.initial.navigation.menu.example1">
  1212. <title>Rendering a menu</title>
  1213. <para>
  1214. This example shows how to render a menu from a container
  1215. registered/found in the view helper. Notice how pages
  1216. are filtered out based on visibility and <acronym>ACL</acronym>.
  1217. </para>
  1218. <programlisting language="php"><![CDATA[
  1219. In a view script or layout:
  1220. <?php echo $this->navigation()->menu()->render() ?>
  1221. Or simply:
  1222. <?php echo $this->navigation()->menu() ?>
  1223. Output:
  1224. <ul class="navigation">
  1225. <li>
  1226. <a title="Go Home" href="/">Home</a>
  1227. </li>
  1228. <li class="active">
  1229. <a href="/products">Products</a>
  1230. <ul>
  1231. <li class="active">
  1232. <a href="/products/server">Foo Server</a>
  1233. <ul>
  1234. <li class="active">
  1235. <a href="/products/server/faq">FAQ</a>
  1236. </li>
  1237. <li>
  1238. <a href="/products/server/editions">Editions</a>
  1239. </li>
  1240. <li>
  1241. <a href="/products/server/requirements">System Requirements</a>
  1242. </li>
  1243. </ul>
  1244. </li>
  1245. <li>
  1246. <a href="/products/studio">Foo Studio</a>
  1247. <ul>
  1248. <li>
  1249. <a href="/products/studio/customers">Customer Stories</a>
  1250. </li>
  1251. <li>
  1252. <a href="/prodcts/studio/support">Support</a>
  1253. </li>
  1254. </ul>
  1255. </li>
  1256. </ul>
  1257. </li>
  1258. <li>
  1259. <a title="About us" href="/company/about">Company</a>
  1260. <ul>
  1261. <li>
  1262. <a href="/company/about/investors">Investor Relations</a>
  1263. </li>
  1264. <li>
  1265. <a class="rss" href="/company/news">News</a>
  1266. <ul>
  1267. <li>
  1268. <a href="/company/news/press">Press Releases</a>
  1269. </li>
  1270. <li>
  1271. <a href="/archive">Archive</a>
  1272. </li>
  1273. </ul>
  1274. </li>
  1275. </ul>
  1276. </li>
  1277. <li>
  1278. <a href="/community">Community</a>
  1279. <ul>
  1280. <li>
  1281. <a href="/community/account">My Account</a>
  1282. </li>
  1283. <li>
  1284. <a class="external" href="http://forums.example.com/">Forums</a>
  1285. </li>
  1286. </ul>
  1287. </li>
  1288. </ul>
  1289. ]]></programlisting>
  1290. </example>
  1291. <example id="zend.view.helpers.initial.navigation.menu.example2">
  1292. <title>Calling renderMenu() directly</title>
  1293. <para>
  1294. This example shows how to render a menu that is not
  1295. registered in the view helper by calling the
  1296. <methodname>renderMenu()</methodname> directly and specifying a few
  1297. options.
  1298. </para>
  1299. <programlisting language="php"><![CDATA[
  1300. <?php
  1301. // render only the 'Community' menu
  1302. $community = $this->navigation()->findOneByLabel('Community');
  1303. $options = array(
  1304. 'indent' => 16,
  1305. 'ulClass' => 'community'
  1306. );
  1307. echo $this->navigation()
  1308. ->menu()
  1309. ->renderMenu($community, $options);
  1310. ?>
  1311. Output:
  1312. <ul class="community">
  1313. <li>
  1314. <a href="/community/account">My Account</a>
  1315. </li>
  1316. <li>
  1317. <a class="external" href="http://forums.example.com/">Forums</a>
  1318. </li>
  1319. </ul>
  1320. ]]></programlisting>
  1321. </example>
  1322. <example id="zend.view.helpers.initial.navigation.menu.example3">
  1323. <title>Rendering the deepest active menu</title>
  1324. <para>
  1325. This example shows how the <methodname>renderSubMenu()</methodname>
  1326. will render the deepest sub menu of the active branch.
  1327. </para>
  1328. <para>
  1329. Calling <methodname>renderSubMenu($container, $ulClass, $indent)</methodname>
  1330. is equivalent to calling <methodname>renderMenu($container, $options)</methodname>
  1331. with the following options:
  1332. </para>
  1333. <programlisting language="php"><![CDATA[
  1334. array(
  1335. 'ulClass' => $ulClass,
  1336. 'indent' => $indent,
  1337. 'minDepth' => null,
  1338. 'maxDepth' => null,
  1339. 'onlyActiveBranch' => true,
  1340. 'renderParents' => false
  1341. );
  1342. ]]></programlisting>
  1343. <programlisting language="php"><![CDATA[
  1344. <?php
  1345. echo $this->navigation()
  1346. ->menu()
  1347. ->renderSubMenu(null, 'sidebar', 4);
  1348. ?>
  1349. The output will be the same if 'FAQ' or 'Foo Server' is active:
  1350. <ul class="sidebar">
  1351. <li class="active">
  1352. <a href="/products/server/faq">FAQ</a>
  1353. </li>
  1354. <li>
  1355. <a href="/products/server/editions">Editions</a>
  1356. </li>
  1357. <li>
  1358. <a href="/products/server/requirements">System Requirements</a>
  1359. </li>
  1360. </ul>
  1361. ]]></programlisting>
  1362. </example>
  1363. <example id="zend.view.helpers.initial.navigation.menu.example4">
  1364. <title>Rendering a menu with maximum depth</title>
  1365. <programlisting language="php"><![CDATA[
  1366. <?php
  1367. echo $this->navigation()
  1368. ->menu()
  1369. ->setMaxDepth(1);
  1370. ?>
  1371. Output:
  1372. <ul class="navigation">
  1373. <li>
  1374. <a title="Go Home" href="/">Home</a>
  1375. </li>
  1376. <li class="active">
  1377. <a href="/products">Products</a>
  1378. <ul>
  1379. <li class="active">
  1380. <a href="/products/server">Foo Server</a>
  1381. </li>
  1382. <li>
  1383. <a href="/products/studio">Foo Studio</a>
  1384. </li>
  1385. </ul>
  1386. </li>
  1387. <li>
  1388. <a title="About us" href="/company/about">Company</a>
  1389. <ul>
  1390. <li>
  1391. <a href="/company/about/investors">Investor Relations</a>
  1392. </li>
  1393. <li>
  1394. <a class="rss" href="/company/news">News</a>
  1395. </li>
  1396. </ul>
  1397. </li>
  1398. <li>
  1399. <a href="/community">Community</a>
  1400. <ul>
  1401. <li>
  1402. <a href="/community/account">My Account</a>
  1403. </li>
  1404. <li>
  1405. <a class="external" href="http://forums.example.com/">Forums</a>
  1406. </li>
  1407. </ul>
  1408. </li>
  1409. </ul>
  1410. ]]></programlisting>
  1411. </example>
  1412. <example id="zend.view.helpers.initial.navigation.menu.example5">
  1413. <title>Rendering a menu with minimum depth</title>
  1414. <programlisting language="php"><![CDATA[
  1415. <?php
  1416. echo $this->navigation()
  1417. ->menu()
  1418. ->setMinDepth(1);
  1419. ?>
  1420. Output:
  1421. <ul class="navigation">
  1422. <li class="active">
  1423. <a href="/products/server">Foo Server</a>
  1424. <ul>
  1425. <li class="active">
  1426. <a href="/products/server/faq">FAQ</a>
  1427. </li>
  1428. <li>
  1429. <a href="/products/server/editions">Editions</a>
  1430. </li>
  1431. <li>
  1432. <a href="/products/server/requirements">System Requirements</a>
  1433. </li>
  1434. </ul>
  1435. </li>
  1436. <li>
  1437. <a href="/products/studio">Foo Studio</a>
  1438. <ul>
  1439. <li>
  1440. <a href="/products/studio/customers">Customer Stories</a>
  1441. </li>
  1442. <li>
  1443. <a href="/prodcts/studio/support">Support</a>
  1444. </li>
  1445. </ul>
  1446. </li>
  1447. <li>
  1448. <a href="/company/about/investors">Investor Relations</a>
  1449. </li>
  1450. <li>
  1451. <a class="rss" href="/company/news">News</a>
  1452. <ul>
  1453. <li>
  1454. <a href="/company/news/press">Press Releases</a>
  1455. </li>
  1456. <li>
  1457. <a href="/archive">Archive</a>
  1458. </li>
  1459. </ul>
  1460. </li>
  1461. <li>
  1462. <a href="/community/account">My Account</a>
  1463. </li>
  1464. <li>
  1465. <a class="external" href="http://forums.example.com/">Forums</a>
  1466. </li>
  1467. </ul>
  1468. ]]></programlisting>
  1469. </example>
  1470. <example id="zend.view.helpers.initial.navigation.menu.example6">
  1471. <title>Rendering only the active branch of a menu</title>
  1472. <programlisting language="php"><![CDATA[
  1473. <?php
  1474. echo $this->navigation()
  1475. ->menu()
  1476. ->setOnlyActiveBranch(true);
  1477. ?>
  1478. Output:
  1479. <ul class="navigation">
  1480. <li class="active">
  1481. <a href="/products">Products</a>
  1482. <ul>
  1483. <li class="active">
  1484. <a href="/products/server">Foo Server</a>
  1485. <ul>
  1486. <li class="active">
  1487. <a href="/products/server/faq">FAQ</a>
  1488. </li>
  1489. <li>
  1490. <a href="/products/server/editions">Editions</a>
  1491. </li>
  1492. <li>
  1493. <a href="/products/server/requirements">System Requirements</a>
  1494. </li>
  1495. </ul>
  1496. </li>
  1497. </ul>
  1498. </li>
  1499. </ul>
  1500. ]]></programlisting>
  1501. </example>
  1502. <example id="zend.view.helpers.initial.navigation.menu.example7">
  1503. <title>
  1504. Rendering only the active branch of a menu with minimum depth
  1505. </title>
  1506. <programlisting language="php"><![CDATA[
  1507. <?php
  1508. echo $this->navigation()
  1509. ->menu()
  1510. ->setOnlyActiveBranch(true)
  1511. ->setMinDepth(1);
  1512. ?>
  1513. Output:
  1514. <ul class="navigation">
  1515. <li class="active">
  1516. <a href="/products/server">Foo Server</a>
  1517. <ul>
  1518. <li class="active">
  1519. <a href="/products/server/faq">FAQ</a>
  1520. </li>
  1521. <li>
  1522. <a href="/products/server/editions">Editions</a>
  1523. </li>
  1524. <li>
  1525. <a href="/products/server/requirements">System Requirements</a>
  1526. </li>
  1527. </ul>
  1528. </li>
  1529. </ul>
  1530. ]]></programlisting>
  1531. </example>
  1532. <example id="zend.view.helpers.initial.navigation.menu.example8">
  1533. <title>
  1534. Rendering only the active branch of a menu with maximum depth
  1535. </title>
  1536. <programlisting language="php"><![CDATA[
  1537. <?php
  1538. echo $this->navigation()
  1539. ->menu()
  1540. ->setOnlyActiveBranch(true)
  1541. ->setMaxDepth(1);
  1542. ?>
  1543. Output:
  1544. <ul class="navigation">
  1545. <li class="active">
  1546. <a href="/products">Products</a>
  1547. <ul>
  1548. <li class="active">
  1549. <a href="/products/server">Foo Server</a>
  1550. </li>
  1551. <li>
  1552. <a href="/products/studio">Foo Studio</a>
  1553. </li>
  1554. </ul>
  1555. </li>
  1556. </ul>
  1557. ]]></programlisting>
  1558. </example>
  1559. <example id="zend.view.helpers.initial.navigation.menu.example9">
  1560. <title>
  1561. Rendering only the active branch of a menu with maximum depth
  1562. and no parents
  1563. </title>
  1564. <para>
  1565. </para>
  1566. <programlisting language="php"><![CDATA[
  1567. <?php
  1568. echo $this->navigation()
  1569. ->menu()
  1570. ->setOnlyActiveBranch(true)
  1571. ->setRenderParents(false)
  1572. ->setMaxDepth(1);
  1573. ?>
  1574. Output:
  1575. <ul class="navigation">
  1576. <li class="active">
  1577. <a href="/products/server">Foo Server</a>
  1578. </li>
  1579. <li>
  1580. <a href="/products/studio">Foo Studio</a>
  1581. </li>
  1582. </ul>
  1583. ]]></programlisting>
  1584. </example>
  1585. <example id="zend.view.helpers.initial.navigation.menu.example10">
  1586. <title>Rendering a custom menu using a partial view script</title>
  1587. <para>
  1588. This example shows how to render a custom menu using
  1589. a partial vew script. By calling <methodname>setPartial()</methodname>,
  1590. you can specify a partial view script that will be used
  1591. when calling <methodname>render()</methodname>. When a partial is specified,
  1592. the <methodname>renderPartial()</methodname> method will be called. This
  1593. method will assign the container to the view with the key
  1594. <code>container</code>.
  1595. </para>
  1596. <para>In a layout:</para>
  1597. <programlisting language="php"><![CDATA[
  1598. $partial = array('menu.phtml', 'default');
  1599. $this->navigation()->menu()->setPartial($partial);
  1600. echo $this->navigation()->menu()->render();
  1601. ]]></programlisting>
  1602. <para>In application/modules/default/views/menu.phtml:</para>
  1603. <programlisting language="php"><![CDATA[
  1604. foreach ($this->container as $page) {
  1605. echo $this->navigation()->menu()->htmlify($page), PHP_EOL;
  1606. }
  1607. ]]></programlisting>
  1608. <para>Output:</para>
  1609. <programlisting language="php"><![CDATA[
  1610. <a title="Go Home" href="/">Home</a>
  1611. <a href="/products">Products</a>
  1612. <a title="About us" href="/company/about">Company</a>
  1613. <a href="/community">Community</a>
  1614. ]]></programlisting>
  1615. </example>
  1616. </sect4>
  1617. <sect4 id="zend.view.helpers.initial.navigation.sitemap">
  1618. <title>Sitemap Helper</title>
  1619. <para>
  1620. The Sitemap helper is used for generating <acronym>XML</acronym> sitemaps, as
  1621. defined by the <ulink
  1622. url="http://www.sitemaps.org/protocol.php">Sitemaps <acronym>XML</acronym> format</ulink>.
  1623. Read more about <ulink url="http://en.wikipedia.org/wiki/Sitemaps">Sitemaps
  1624. on Wikpedia</ulink>.
  1625. </para>
  1626. <para>
  1627. By default, the sitemap helper uses
  1628. <link linkend="zend.validate.sitemap">sitemap validators</link>
  1629. to validate each element that is rendered. This can be disabled by
  1630. calling <code>$helper->setUseSitemapValidators(false)</code>.
  1631. </para>
  1632. <note>
  1633. <para>
  1634. If you disable sitemap validators, the custom properties (see table)
  1635. are not validated at all.
  1636. </para>
  1637. </note>
  1638. <para>
  1639. The sitemap helper also supports <ulink
  1640. url="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">Sitemap XSD
  1641. Schema</ulink> validation of the generated sitemap. This is disabled by default,
  1642. since it will require a request to the Schema file. It can be
  1643. enabled with
  1644. <code>$helper->setUseSchemaValidation(true)</code>.
  1645. </para>
  1646. <table id="zend.view.helpers.initial.navigation.sitemap.elements">
  1647. <title>Sitemap XML elements</title>
  1648. <tgroup cols="2">
  1649. <thead>
  1650. <row>
  1651. <entry>Element</entry>
  1652. <entry>Description</entry>
  1653. </row>
  1654. </thead>
  1655. <tbody>
  1656. <row>
  1657. <entry><code>loc</code></entry>
  1658. <entry>
  1659. Absolute <acronym>URL</acronym> to page. An absolute <acronym>URL</acronym> will
  1660. be generated by the helper.
  1661. </entry>
  1662. </row>
  1663. <row>
  1664. <entry><code>lastmod</code></entry>
  1665. <entry>
  1666. <para>
  1667. The date of last modification of the file, in <ulink
  1668. url="http://www.w3.org/TR/NOTE-datetime">W3C Datetime</ulink>
  1669. format. This time portion can be omitted if desired, and only use
  1670. YYYY-MM-DD.
  1671. </para>
  1672. <para>
  1673. The helper will try to retrieve the
  1674. <code>lastmod</code> value from the page's
  1675. custom property <code>lastmod</code> if it
  1676. is set in the page. If the value is not a
  1677. valid date, it is ignored.
  1678. </para>
  1679. </entry>
  1680. </row>
  1681. <row>
  1682. <entry><code>changefreq</code></entry>
  1683. <entry>
  1684. <para>
  1685. How frequently the page is likely to change.
  1686. This value provides general information to
  1687. search engines and may not correlate exactly
  1688. to how often they crawl the page. Valid
  1689. values are:
  1690. </para>
  1691. <itemizedlist>
  1692. <listitem><para>always</para></listitem>
  1693. <listitem><para>hourly</para></listitem>
  1694. <listitem><para>daily</para></listitem>
  1695. <listitem><para>weekly</para></listitem>
  1696. <listitem><para>monthly</para></listitem>
  1697. <listitem><para>yearly</para></listitem>
  1698. <listitem><para>never</para></listitem>
  1699. </itemizedlist>
  1700. <para>
  1701. The helper will try to retrieve the
  1702. <code>changefreq</code> value from the page's
  1703. custom property <code>changefreq</code> if it
  1704. is set in the page. If the value is not
  1705. valid, it is ignored.
  1706. </para>
  1707. </entry>
  1708. </row>
  1709. <row>
  1710. <entry><code>priority</code></entry>
  1711. <entry>
  1712. <para>
  1713. The priority of this <acronym>URL</acronym> relative to other
  1714. <acronym>URL</acronym>s on your site. Valid values range from
  1715. 0.0 to 1.0.
  1716. </para>
  1717. <para>
  1718. The helper will try to retrieve the
  1719. <code>priority</code> value from the page's
  1720. custom property <code>priority</code> if it
  1721. is set in the page. If the value is not
  1722. valid, it is ignored.
  1723. </para>
  1724. </entry>
  1725. </row>
  1726. </tbody>
  1727. </tgroup>
  1728. </table>
  1729. <para>
  1730. Methods in the sitemap helper:
  1731. </para>
  1732. <itemizedlist>
  1733. <listitem>
  1734. <para>
  1735. <code>{get|set}FormatOutput()</code> gets/sets a flag
  1736. indicating whether <acronym>XML</acronym> output should be formatted. This
  1737. corresponds to the <code>formatOutput</code> property
  1738. of the native <classname>DOMDocument</classname> class.
  1739. Read more at
  1740. <ulink url="http://php.net/domdocument">PHP: DOMDocument - Manual</ulink>.
  1741. Default is <constant>FALSE</constant>.
  1742. </para>
  1743. </listitem>
  1744. <listitem>
  1745. <para>
  1746. <code>{get|set}UseXmlDeclaration()</code> gets/sets a
  1747. flag indicating whether the <acronym>XML</acronym> declaration should be
  1748. included when rendering. Default is <constant>TRUE</constant>.
  1749. </para>
  1750. </listitem>
  1751. <listitem>
  1752. <para>
  1753. <code>{get|set}UseSitemapValidators()</code> gets/sets a
  1754. flag indicating whether sitemap validators should be
  1755. used when generating the DOM sitemap. Default is
  1756. <constant>TRUE</constant>.
  1757. </para>
  1758. </listitem>
  1759. <listitem>
  1760. <para>
  1761. <code>{get|set}UseSchemaValidation()</code> gets/sets a
  1762. flag indicating whether the helper should use <acronym>XML</acronym> Schema
  1763. validation when generating the DOM sitemap. Default is
  1764. <constant>FALSE</constant>. If <constant>TRUE</constant>.
  1765. </para>
  1766. </listitem>
  1767. <listitem>
  1768. <para>
  1769. <code>{get|set}ServerUrl()</code> gets/sets server <acronym>URL</acronym>
  1770. that will be prepended to non-absolute <acronym>URL</acronym>s in the
  1771. <methodname>url()</methodname> method. If no server <acronym>URL</acronym> is specified,
  1772. it will be determined by the helper.
  1773. </para>
  1774. </listitem>
  1775. <listitem>
  1776. <para>
  1777. <methodname>url()</methodname> is used to generate absolute <acronym>URL</acronym>s to
  1778. pages.
  1779. </para>
  1780. </listitem>
  1781. <listitem>
  1782. <para>
  1783. <methodname>getDomSitemap()</methodname> generates a DOMDocument
  1784. from a given container.
  1785. </para>
  1786. </listitem>
  1787. </itemizedlist>
  1788. <example id="zend.view.helpers.initial.navigation.sitemap.example">
  1789. <title>Rendering an XML sitemap</title>
  1790. <para>
  1791. This example shows how to render an <acronym>XML</acronym> sitemap based
  1792. on the setup we did further up.
  1793. </para>
  1794. <programlisting language="php"><![CDATA[
  1795. // In a view script or layout:
  1796. // format output
  1797. $this->navigation()
  1798. ->sitemap()
  1799. ->setFormatOutput(true); // default is false
  1800. // other possible methods:
  1801. // ->setUseXmlDeclaration(false); // default is true
  1802. // ->setServerUrl('http://my.otherhost.com');
  1803. // default is to detect automatically
  1804. // print sitemap
  1805. echo $this->navigation()->sitemap();
  1806. ]]></programlisting>
  1807. <para>
  1808. Notice how pages that are invisible or pages with
  1809. <acronym>ACL</acronym> roles incompatible with the view helper are filtered
  1810. out:
  1811. </para>
  1812. <programlisting language="xml"><![CDATA[
  1813. <?xml version="1.0" encoding="UTF-8"?>
  1814. <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  1815. <url>
  1816. <loc>http://www.example.com/</loc>
  1817. </url>
  1818. <url>
  1819. <loc>http://www.example.com/products</loc>
  1820. </url>
  1821. <url>
  1822. <loc>http://www.example.com/products/server</loc>
  1823. </url>
  1824. <url>
  1825. <loc>http://www.example.com/products/server/faq</loc>
  1826. </url>
  1827. <url>
  1828. <loc>http://www.example.com/products/server/editions</loc>
  1829. </url>
  1830. <url>
  1831. <loc>http://www.example.com/products/server/requirements</loc>
  1832. </url>
  1833. <url>
  1834. <loc>http://www.example.com/products/studio</loc>
  1835. </url>
  1836. <url>
  1837. <loc>http://www.example.com/products/studio/customers</loc>
  1838. </url>
  1839. <url>
  1840. <loc>http://www.example.com/prodcts/studio/support</loc>
  1841. </url>
  1842. <url>
  1843. <loc>http://www.example.com/company/about</loc>
  1844. </url>
  1845. <url>
  1846. <loc>http://www.example.com/company/about/investors</loc>
  1847. </url>
  1848. <url>
  1849. <loc>http://www.example.com/company/news</loc>
  1850. </url>
  1851. <url>
  1852. <loc>http://www.example.com/company/news/press</loc>
  1853. </url>
  1854. <url>
  1855. <loc>http://www.example.com/archive</loc>
  1856. </url>
  1857. <url>
  1858. <loc>http://www.example.com/community</loc>
  1859. </url>
  1860. <url>
  1861. <loc>http://www.example.com/community/account</loc>
  1862. </url>
  1863. <url>
  1864. <loc>http://forums.example.com/</loc>
  1865. </url>
  1866. </urlset>
  1867. ]]></programlisting>
  1868. <para>
  1869. Render the sitemap using no <acronym>ACL</acronym> role (should filter out
  1870. /community/account):
  1871. </para>
  1872. <programlisting language="php"><![CDATA[
  1873. echo $this->navigation()
  1874. ->sitemap()
  1875. ->setFormatOutput(true)
  1876. ->setRole();
  1877. ]]></programlisting>
  1878. <programlisting language="xml"><![CDATA[
  1879. <?xml version="1.0" encoding="UTF-8"?>
  1880. <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  1881. <url>
  1882. <loc>http://www.example.com/</loc>
  1883. </url>
  1884. <url>
  1885. <loc>http://www.example.com/products</loc>
  1886. </url>
  1887. <url>
  1888. <loc>http://www.example.com/products/server</loc>
  1889. </url>
  1890. <url>
  1891. <loc>http://www.example.com/products/server/faq</loc>
  1892. </url>
  1893. <url>
  1894. <loc>http://www.example.com/products/server/editions</loc>
  1895. </url>
  1896. <url>
  1897. <loc>http://www.example.com/products/server/requirements</loc>
  1898. </url>
  1899. <url>
  1900. <loc>http://www.example.com/products/studio</loc>
  1901. </url>
  1902. <url>
  1903. <loc>http://www.example.com/products/studio/customers</loc>
  1904. </url>
  1905. <url>
  1906. <loc>http://www.example.com/prodcts/studio/support</loc>
  1907. </url>
  1908. <url>
  1909. <loc>http://www.example.com/company/about</loc>
  1910. </url>
  1911. <url>
  1912. <loc>http://www.example.com/company/about/investors</loc>
  1913. </url>
  1914. <url>
  1915. <loc>http://www.example.com/company/news</loc>
  1916. </url>
  1917. <url>
  1918. <loc>http://www.example.com/company/news/press</loc>
  1919. </url>
  1920. <url>
  1921. <loc>http://www.example.com/archive</loc>
  1922. </url>
  1923. <url>
  1924. <loc>http://www.example.com/community</loc>
  1925. </url>
  1926. <url>
  1927. <loc>http://forums.example.com/</loc>
  1928. </url>
  1929. </urlset>
  1930. ]]></programlisting>
  1931. <para>
  1932. Render the sitemap using a maximum depth of 1.
  1933. </para>
  1934. <programlisting language="php"><![CDATA[
  1935. echo $this->navigation()
  1936. ->sitemap()
  1937. ->setFormatOutput(true)
  1938. ->setMaxDepth(1);
  1939. ]]></programlisting>
  1940. <programlisting language="xml"><![CDATA[
  1941. <?xml version="1.0" encoding="UTF-8"?>
  1942. <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  1943. <url>
  1944. <loc>http://www.example.com/</loc>
  1945. </url>
  1946. <url>
  1947. <loc>http://www.example.com/products</loc>
  1948. </url>
  1949. <url>
  1950. <loc>http://www.example.com/products/server</loc>
  1951. </url>
  1952. <url>
  1953. <loc>http://www.example.com/products/studio</loc>
  1954. </url>
  1955. <url>
  1956. <loc>http://www.example.com/company/about</loc>
  1957. </url>
  1958. <url>
  1959. <loc>http://www.example.com/company/about/investors</loc>
  1960. </url>
  1961. <url>
  1962. <loc>http://www.example.com/company/news</loc>
  1963. </url>
  1964. <url>
  1965. <loc>http://www.example.com/community</loc>
  1966. </url>
  1967. <url>
  1968. <loc>http://www.example.com/community/account</loc>
  1969. </url>
  1970. <url>
  1971. <loc>http://forums.example.com/</loc>
  1972. </url>
  1973. </urlset>
  1974. ]]></programlisting>
  1975. </example>
  1976. </sect4>
  1977. <sect4 id="zend.view.helpers.initial.navigation.navigation">
  1978. <title>Navigation Helper</title>
  1979. <para>
  1980. The Navigation helper is a proxy helper
  1981. that relays calls to other navigational helpers. It can be
  1982. considered an entry point to all navigation-related view tasks.
  1983. The aforementioned navigational helpers are in the namespace
  1984. <classname>Zend_View_Helper_Navigation</classname>, and would thus require
  1985. the path <code>Zend/View/Helper/Navigation</code> to be added as
  1986. a helper path to the view. With the proxy helper residing in the
  1987. <classname>Zend_View_Helper</classname> namespace, it will always be
  1988. available, without the need to add any helper paths to the view.
  1989. </para>
  1990. <para>
  1991. The Navigation helper finds other helpers that implement the
  1992. <classname>Zend_View_Helper_Navigation_Helper</classname>
  1993. interface, which means custom view helpers can also be proxied.
  1994. This would, however, require that the custom helper path is added
  1995. to the view.
  1996. </para>
  1997. <para>
  1998. When proxying to other helpers, the Navigation helper can inject
  1999. its container, <acronym>ACL</acronym>/role, and translator. This means that you
  2000. won't have to explicitly set all three in all navigational
  2001. helpers, nor resort to injecting by means of
  2002. <classname>Zend_Registry</classname> or static methods.
  2003. </para>
  2004. <itemizedlist>
  2005. <listitem>
  2006. <para>
  2007. <methodname>findHelper()</methodname> finds the given helper,
  2008. verifies that it is a navigational helper, and injects
  2009. container, <acronym>ACL</acronym>/role and translator.
  2010. </para>
  2011. </listitem>
  2012. <listitem>
  2013. <para>
  2014. <code>{get|set}InjectContainer()</code> gets/sets a flag
  2015. indicating whether the container should be injected to
  2016. proxied helpers. Default is <constant>TRUE</constant>.
  2017. </para>
  2018. </listitem>
  2019. <listitem>
  2020. <para>
  2021. <code>{get|set}InjectAcl()</code> gets/sets a flag
  2022. indicating whether the <acronym>ACL</acronym>/role should be injected to
  2023. proxied helpers. Default is <constant>TRUE</constant>.
  2024. </para>
  2025. </listitem>
  2026. <listitem>
  2027. <para>
  2028. <code>{get|set}InjectTranslator()</code> gets/sets a flag
  2029. indicating whether the translator should be injected to
  2030. proxied helpers. Default is <constant>TRUE</constant>.
  2031. </para>
  2032. </listitem>
  2033. <listitem>
  2034. <para>
  2035. <code>{get|set}DefaultProxy()</code> gets/sets the default
  2036. proxy. Default is <code>'menu'</code>.
  2037. </para>
  2038. </listitem>
  2039. <listitem>
  2040. <para>
  2041. <methodname>render()</methodname> proxies to the render method of
  2042. the default proxy.
  2043. </para>
  2044. </listitem>
  2045. </itemizedlist>
  2046. </sect4>
  2047. </sect3>