Zend_View-Helpers-Navigation.xml 83 KB

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