Zend_Navigation-Containers.xml 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.navigation.containers">
  4. <title>Containers</title>
  5. <para>
  6. Containers have methods for adding, retrieving, deleting and
  7. iterating pages. Containers implement the
  8. <ulink url="http://php.net/spl">SPL</ulink> interfaces
  9. <classname>RecursiveIterator</classname> and
  10. <classname>Countable</classname>, meaning that a container can
  11. be iterated using the SPL
  12. <classname>RecursiveIteratorIterator</classname> class.
  13. </para>
  14. <sect2 id="zend.navigation.containers.creating">
  15. <title>Creating containers</title>
  16. <para>
  17. <classname>Zend_Navigation_Container</classname> is
  18. abstract, and can not be instantiated directly. Use
  19. <classname>Zend_Navigation</classname> if you want to
  20. instantiate a container.
  21. </para>
  22. <para>
  23. <classname>Zend_Navigation</classname> can be constructed
  24. entirely empty, or take an array or a
  25. <classname>Zend_Config</classname> object with pages to put in the
  26. container. Each page in the given array/config will eventually be
  27. passed to the <methodname>addPage()</methodname> method of the container class,
  28. which means that each element in the array/config can be an array or
  29. a config object, or a <classname>Zend_Navigation_Page</classname>
  30. instance.
  31. </para>
  32. <example id="zend.navigation.containers.creating.example.array">
  33. <title>Creating a container using an array</title>
  34. <programlisting language="php"><![CDATA[
  35. /*
  36. * Create a container from an array
  37. *
  38. * Each element in the array will be passed to
  39. * Zend_Navigation_Page::factory() when constructing.
  40. */
  41. $container = new Zend_Navigation(array(
  42. array(
  43. 'label' => 'Page 1',
  44. 'id' => 'home-link',
  45. 'uri' => '/'
  46. ),
  47. array(
  48. 'label' => 'Zend',
  49. 'uri' => 'http://www.zend-project.com/',
  50. 'order' => 100
  51. ),
  52. array(
  53. 'label' => 'Page 2',
  54. 'controller' => 'page2',
  55. 'pages' => array(
  56. array(
  57. 'label' => 'Page 2.1',
  58. 'action' => 'page2_1',
  59. 'controller' => 'page2',
  60. 'class' => 'special-one',
  61. 'title' => 'This element has a special class',
  62. 'active' => true
  63. ),
  64. array(
  65. 'label' => 'Page 2.2',
  66. 'action' => 'page2_2',
  67. 'controller' => 'page2',
  68. 'class' => 'special-two',
  69. 'title' => 'This element has a special class too'
  70. )
  71. )
  72. ),
  73. array(
  74. 'label' => 'Page 2 with params',
  75. 'action' => 'index',
  76. 'controller' => 'page2',
  77. // specify a param or two
  78. 'params' => array(
  79. 'format' => 'json',
  80. 'foo' => 'bar'
  81. )
  82. ),
  83. array(
  84. 'label' => 'Page 2 with params and a route',
  85. 'action' => 'index',
  86. 'controller' => 'page2',
  87. // specify a route name and a param for the route
  88. 'route' => 'nav-route-example',
  89. 'params' => array(
  90. 'format' => 'json'
  91. )
  92. ),
  93. array(
  94. 'label' => 'Page 3',
  95. 'action' => 'index',
  96. 'controller' => 'index',
  97. 'module' => 'mymodule',
  98. 'reset_params' => false
  99. ),
  100. array(
  101. 'label' => 'Page 4',
  102. 'uri' => '#',
  103. 'pages' => array(
  104. array(
  105. 'label' => 'Page 4.1',
  106. 'uri' => '/page4',
  107. 'title' => 'Page 4 using uri',
  108. 'pages' => array(
  109. array(
  110. 'label' => 'Page 4.1.1',
  111. 'title' => 'Page 4 using mvc params',
  112. 'action' => 'index',
  113. 'controller' => 'page4',
  114. // let's say this page is active
  115. 'active' => '1'
  116. )
  117. )
  118. )
  119. )
  120. ),
  121. array(
  122. 'label' => 'Page 0?',
  123. 'uri' => '/setting/the/order/option',
  124. // setting order to -1 should make it appear first
  125. 'order' => -1
  126. ),
  127. array(
  128. 'label' => 'Page 5',
  129. 'uri' => '/',
  130. // this page should not be visible
  131. 'visible' => false,
  132. 'pages' => array(
  133. array(
  134. 'label' => 'Page 5.1',
  135. 'uri' => '#',
  136. 'pages' => array(
  137. array(
  138. 'label' => 'Page 5.1.1',
  139. 'uri' => '#',
  140. 'pages' => array(
  141. array(
  142. 'label' => 'Page 5.1.2',
  143. 'uri' => '#',
  144. // let's say this page is active
  145. 'active' => true
  146. )
  147. )
  148. )
  149. )
  150. )
  151. )
  152. ),
  153. array(
  154. 'label' => 'ACL page 1 (guest)',
  155. 'uri' => '#acl-guest',
  156. 'resource' => 'nav-guest',
  157. 'pages' => array(
  158. array(
  159. 'label' => 'ACL page 1.1 (foo)',
  160. 'uri' => '#acl-foo',
  161. 'resource' => 'nav-foo'
  162. ),
  163. array(
  164. 'label' => 'ACL page 1.2 (bar)',
  165. 'uri' => '#acl-bar',
  166. 'resource' => 'nav-bar'
  167. ),
  168. array(
  169. 'label' => 'ACL page 1.3 (baz)',
  170. 'uri' => '#acl-baz',
  171. 'resource' => 'nav-baz'
  172. ),
  173. array(
  174. 'label' => 'ACL page 1.4 (bat)',
  175. 'uri' => '#acl-bat',
  176. 'resource' => 'nav-bat'
  177. )
  178. )
  179. ),
  180. array(
  181. 'label' => 'ACL page 2 (member)',
  182. 'uri' => '#acl-member',
  183. 'resource' => 'nav-member'
  184. ),
  185. array(
  186. 'label' => 'ACL page 3 (admin',
  187. 'uri' => '#acl-admin',
  188. 'resource' => 'nav-admin',
  189. 'pages' => array(
  190. array(
  191. 'label' => 'ACL page 3.1 (nothing)',
  192. 'uri' => '#acl-nada'
  193. )
  194. )
  195. ),
  196. array(
  197. 'label' => 'Zend Framework',
  198. 'route' => 'zf-route'
  199. )
  200. ));
  201. ]]></programlisting>
  202. </example>
  203. <example id="zend.navigation.containers.creating.example.config">
  204. <title>Creating a container using a config object</title>
  205. <para>
  206. Example for INI:
  207. </para>
  208. <programlisting language="ini"><![CDATA[
  209. [nav]
  210. zend.label = "Zend"
  211. zend.uri = "http://www.zend-project.com/"
  212. zend.order = "100"
  213. page1.label = "Page 1"
  214. page1.uri = "page1"
  215. page1.pages.page1_1.label = "Page 1.1"
  216. page1.pages.page1_1.uri = "page1/page1_1"
  217. page2.label = "Page 2"
  218. page2.uri = "page2"
  219. page2.pages.page2_1.label = "Page 2.1"
  220. page2.pages.page2_1.uri = "page2/page2_1"
  221. page2.pages.page2_2.label = "Page 2.2"
  222. page2.pages.page2_2.uri = "page2/page2_2"
  223. page2.pages.page2_2.pages.page2_2_1.label = "Page 2.2.1"
  224. page2.pages.page2_2.pages.page2_2_1.uri = "page2/page2_2/page2_2_1"
  225. page2.pages.page2_2.pages.page2_2_2.label = "Page 2.2.2"
  226. page2.pages.page2_2.pages.page2_2_2.uri = "page2/page2_2/page2_2_2"
  227. page2.pages.page2_2.pages.page2_2_2.active = "1"
  228. page2.pages.page2_3.label = "Page 2.3"
  229. page2.pages.page2_3.uri = "page2/page2_3"
  230. page2.pages.page2_3.pages.page2_3_1.label = "Page 2.3.1"
  231. page2.pages.page2_3.pages.page2_3_1.uri = "page2/page2_3/page2_3_1"
  232. page2.pages.page2_3.pages.page2_3_2.label = "Page 2.3.2"
  233. page2.pages.page2_3.pages.page2_3_2.uri = "page2/page2_3/page2_3_2"
  234. page2.pages.page2_3.pages.page2_3_2.visible = "0"
  235. page2.pages.page2_3.pages.page2_3_2.pages.page2_3_2_1.label = "Page 2.3.2.1"
  236. page2.pages.page2_3.pages.page2_3_2.pages.page2_3_2_1.uri = "page2/page2_3/page2_3_2/1"
  237. page2.pages.page2_3.pages.page2_3_2.pages.page2_3_2_1.active = "1"
  238. page2.pages.page2_3.pages.page2_3_2.pages.page2_3_2_2.label = "Page 2.3.2.2"
  239. page2.pages.page2_3.pages.page2_3_2.pages.page2_3_2_2.uri = "page2/page2_3/page2_3_2/2"
  240. page2.pages.page2_3.pages.page2_3_2.pages.page2_3_2_2.active = "1"
  241. page2.pages.page2_3.pages.page2_3_2.pages.page2_3_2_2.pages.page_2_3_2_2_1.label = "Ignore"
  242. page2.pages.page2_3.pages.page2_3_2.pages.page2_3_2_2.pages.page_2_3_2_2_1.uri = "#"
  243. page2.pages.page2_3.pages.page2_3_2.pages.page2_3_2_2.pages.page_2_3_2_2_1.active = "1"
  244. page2.pages.page2_3.pages.page2_3_3.label = "Page 2.3.3"
  245. page2.pages.page2_3.pages.page2_3_3.uri = "page2/page2_3/page2_3_3"
  246. page2.pages.page2_3.pages.page2_3_3.resource = "admin"
  247. page2.pages.page2_3.pages.page2_3_3.pages.page2_3_3_1.label = "Page 2.3.3.1"
  248. page2.pages.page2_3.pages.page2_3_3.pages.page2_3_3_1.uri = "page2/page2_3/page2_3_3/1"
  249. page2.pages.page2_3.pages.page2_3_3.pages.page2_3_3_1.active = "1"
  250. page2.pages.page2_3.pages.page2_3_3.pages.page2_3_3_2.label = "Page 2.3.3.2"
  251. page2.pages.page2_3.pages.page2_3_3.pages.page2_3_3_2.uri = "page2/page2_3/page2_3_3/2"
  252. page2.pages.page2_3.pages.page2_3_3.pages.page2_3_3_2.resource = "guest"
  253. page2.pages.page2_3.pages.page2_3_3.pages.page2_3_3_2.active = "1"
  254. page3.label = "Page 3"
  255. page3.uri = "page3"
  256. page3.pages.page3_1.label = "Page 3.1"
  257. page3.pages.page3_1.uri = "page3/page3_1"
  258. page3.pages.page3_1.resource = "guest"
  259. page3.pages.page3_2.label = "Page 3.2"
  260. page3.pages.page3_2.uri = "page3/page3_2"
  261. page3.pages.page3_2.resource = "member"
  262. page3.pages.page3_2.pages.page3_2_1.label = "Page 3.2.1"
  263. page3.pages.page3_2.pages.page3_2_1.uri = "page3/page3_2/page3_2_1"
  264. page3.pages.page3_2.pages.page3_2_2.label = "Page 3.2.2"
  265. page3.pages.page3_2.pages.page3_2_2.uri = "page3/page3_2/page3_2_2"
  266. page3.pages.page3_2.pages.page3_2_2.resource = "admin"
  267. page3.pages.page3_3.label = "Page 3.3"
  268. page3.pages.page3_3.uri = "page3/page3_3"
  269. page3.pages.page3_3.resource = "special"
  270. page3.pages.page3_3.pages.page3_3_1.label = "Page 3.3.1"
  271. page3.pages.page3_3.pages.page3_3_1.uri = "page3/page3_3/page3_3_1"
  272. page3.pages.page3_3.pages.page3_3_1.visible = "0"
  273. page3.pages.page3_3.pages.page3_3_2.label = "Page 3.3.2"
  274. page3.pages.page3_3.pages.page3_3_2.uri = "page3/page3_3/page3_3_2"
  275. page3.pages.page3_3.pages.page3_3_2.resource = "admin"
  276. home.label = "Home"
  277. home.order = "-100"
  278. home.module = "default"
  279. home.controller = "index"
  280. home.action = "index"
  281. ]]></programlisting>
  282. <programlisting language="php"><![CDATA[
  283. $config = new Zend_Config_Ini('/path/to/navigation.ini', 'nav');
  284. $container = new Zend_Navigation($config);
  285. ]]></programlisting>
  286. <para>
  287. Example for JSON:
  288. </para>
  289. <programlisting language="json"><![CDATA[
  290. {
  291. "nav": {
  292. "zend": {
  293. "label": "Zend",
  294. "uri": "http:\/\/www.zend-project.com\/",
  295. "order": "100"
  296. },
  297. "page1": {
  298. "label": "Page 1",
  299. "uri": "page1",
  300. "pages": {
  301. "page1_1": {
  302. "label": "Page 1.1",
  303. "uri": "page1\/page1_1"
  304. }
  305. }
  306. },
  307. "page2": {
  308. "label": "Page 2",
  309. "uri": "page2",
  310. "pages": {
  311. "page2_1": {
  312. "label": "Page 2.1",
  313. "uri": "page2\/page2_1"
  314. },
  315. "page2_2": {
  316. "label": "Page 2.2",
  317. "uri": "page2\/page2_2",
  318. "pages": {
  319. "page2_2_1": {
  320. "label": "Page 2.2.1",
  321. "uri": "page2\/page2_2\/page2_2_1"
  322. },
  323. "page2_2_2": {
  324. "label": "Page 2.2.2",
  325. "uri": "page2\/page2_2\/page2_2_2",
  326. "active": "1"
  327. }
  328. }
  329. },
  330. "page2_3": {
  331. "label": "Page 2.3",
  332. "uri": "page2\/page2_3",
  333. "pages": {
  334. "page2_3_1": {
  335. "label": "Page 2.3.1",
  336. "uri": "page2\/page2_3\/page2_3_1"
  337. },
  338. "page2_3_2": {
  339. "label": "Page 2.3.2",
  340. "uri": "page2\/page2_3\/page2_3_2",
  341. "visible": "0",
  342. "pages": {
  343. "page2_3_2_1": {
  344. "label": "Page 2.3.2.1",
  345. "uri": "page2\/page2_3\/page2_3_2\/1",
  346. "active": "1"
  347. },
  348. "page2_3_2_2": {
  349. "label": "Page 2.3.2.2",
  350. "uri": "page2\/page2_3\/page2_3_2\/2",
  351. "active": "1",
  352. "pages": {
  353. "page_2_3_2_2_1": {
  354. "label": "Ignore",
  355. "uri": "#",
  356. "active": "1"
  357. }
  358. }
  359. }
  360. }
  361. },
  362. "page2_3_3": {
  363. "label": "Page 2.3.3",
  364. "uri": "page2\/page2_3\/page2_3_3",
  365. "resource": "admin",
  366. "pages": {
  367. "page2_3_3_1": {
  368. "label": "Page 2.3.3.1",
  369. "uri": "page2\/page2_3\/page2_3_3\/1",
  370. "active": "1"
  371. },
  372. "page2_3_3_2": {
  373. "label": "Page 2.3.3.2",
  374. "uri": "page2\/page2_3\/page2_3_3\/2",
  375. "resource": "guest",
  376. "active": "1"
  377. }
  378. }
  379. }
  380. }
  381. }
  382. }
  383. },
  384. "page3": {
  385. "label": "Page 3",
  386. "uri": "page3",
  387. "pages": {
  388. "page3_1": {
  389. "label": "Page 3.1",
  390. "uri": "page3\/page3_1",
  391. "resource": "guest"
  392. },
  393. "page3_2": {
  394. "label": "Page 3.2",
  395. "uri": "page3\/page3_2",
  396. "resource": "member",
  397. "pages": {
  398. "page3_2_1": {
  399. "label": "Page 3.2.1",
  400. "uri": "page3\/page3_2\/page3_2_1"
  401. },
  402. "page3_2_2": {
  403. "label": "Page 3.2.2",
  404. "uri": "page3\/page3_2\/page3_2_2",
  405. "resource": "admin"
  406. }
  407. }
  408. },
  409. "page3_3": {
  410. "label": "Page 3.3",
  411. "uri": "page3\/page3_3",
  412. "resource": "special",
  413. "pages": {
  414. "page3_3_1": {
  415. "label": "Page 3.3.1",
  416. "uri": "page3\/page3_3\/page3_3_1",
  417. "visible": "0"
  418. },
  419. "page3_3_2": {
  420. "label": "Page 3.3.2",
  421. "uri": "page3\/page3_3\/page3_3_2",
  422. "resource": "admin"
  423. }
  424. }
  425. }
  426. }
  427. },
  428. "home": {
  429. "label": "Home",
  430. "order": "-100",
  431. "module": "default",
  432. "controller": "index",
  433. "action": "index"
  434. }
  435. }
  436. }
  437. ]]></programlisting>
  438. <programlisting language="php"><![CDATA[
  439. $config = new Zend_Config_Json('/path/to/navigation.json', 'nav');
  440. $container = new Zend_Navigation($config);
  441. ]]></programlisting>
  442. <para>
  443. Example for XML:
  444. </para>
  445. <programlisting language="xml"><![CDATA[
  446. <?xml version="1.0" encoding="UTF-8"?>
  447. <config>
  448. <nav>
  449. <zend>
  450. <label>Zend</label>
  451. <uri>http://www.zend-project.com/</uri>
  452. <order>100</order>
  453. </zend>
  454. <page1>
  455. <label>Page 1</label>
  456. <uri>page1</uri>
  457. <pages>
  458. <page1_1>
  459. <label>Page 1.1</label>
  460. <uri>page1/page1_1</uri>
  461. </page1_1>
  462. </pages>
  463. </page1>
  464. <page2>
  465. <label>Page 2</label>
  466. <uri>page2</uri>
  467. <pages>
  468. <page2_1>
  469. <label>Page 2.1</label>
  470. <uri>page2/page2_1</uri>
  471. </page2_1>
  472. <page2_2>
  473. <label>Page 2.2</label>
  474. <uri>page2/page2_2</uri>
  475. <pages>
  476. <page2_2_1>
  477. <label>Page 2.2.1</label>
  478. <uri>page2/page2_2/page2_2_1</uri>
  479. </page2_2_1>
  480. <page2_2_2>
  481. <label>Page 2.2.2</label>
  482. <uri>page2/page2_2/page2_2_2</uri>
  483. <active>1</active>
  484. </page2_2_2>
  485. </pages>
  486. </page2_2>
  487. <page2_3>
  488. <label>Page 2.3</label>
  489. <uri>page2/page2_3</uri>
  490. <pages>
  491. <page2_3_1>
  492. <label>Page 2.3.1</label>
  493. <uri>page2/page2_3/page2_3_1</uri>
  494. </page2_3_1>
  495. <page2_3_2>
  496. <label>Page 2.3.2</label>
  497. <uri>page2/page2_3/page2_3_2</uri>
  498. <visible>0</visible>
  499. <pages>
  500. <page2_3_2_1>
  501. <label>Page 2.3.2.1</label>
  502. <uri>page2/page2_3/page2_3_2/1</uri>
  503. <active>1</active>
  504. </page2_3_2_1>
  505. <page2_3_2_2>
  506. <label>Page 2.3.2.2</label>
  507. <uri>page2/page2_3/page2_3_2/2</uri>
  508. <active>1</active>
  509. <pages>
  510. <page_2_3_2_2_1>
  511. <label>Ignore</label>
  512. <uri>#</uri>
  513. <active>1</active>
  514. </page_2_3_2_2_1>
  515. </pages>
  516. </page2_3_2_2>
  517. </pages>
  518. </page2_3_2>
  519. <page2_3_3>
  520. <label>Page 2.3.3</label>
  521. <uri>page2/page2_3/page2_3_3</uri>
  522. <resource>admin</resource>
  523. <pages>
  524. <page2_3_3_1>
  525. <label>Page 2.3.3.1</label>
  526. <uri>page2/page2_3/page2_3_3/1</uri>
  527. <active>1</active>
  528. </page2_3_3_1>
  529. <page2_3_3_2>
  530. <label>Page 2.3.3.2</label>
  531. <uri>page2/page2_3/page2_3_3/2</uri>
  532. <resource>guest</resource>
  533. <active>1</active>
  534. </page2_3_3_2>
  535. </pages>
  536. </page2_3_3>
  537. </pages>
  538. </page2_3>
  539. </pages>
  540. </page2>
  541. <page3>
  542. <label>Page 3</label>
  543. <uri>page3</uri>
  544. <pages>
  545. <page3_1>
  546. <label>Page 3.1</label>
  547. <uri>page3/page3_1</uri>
  548. <resource>guest</resource>
  549. </page3_1>
  550. <page3_2>
  551. <label>Page 3.2</label>
  552. <uri>page3/page3_2</uri>
  553. <resource>member</resource>
  554. <pages>
  555. <page3_2_1>
  556. <label>Page 3.2.1</label>
  557. <uri>page3/page3_2/page3_2_1</uri>
  558. </page3_2_1>
  559. <page3_2_2>
  560. <label>Page 3.2.2</label>
  561. <uri>page3/page3_2/page3_2_2</uri>
  562. <resource>admin</resource>
  563. </page3_2_2>
  564. </pages>
  565. </page3_2>
  566. <page3_3>
  567. <label>Page 3.3</label>
  568. <uri>page3/page3_3</uri>
  569. <resource>special</resource>
  570. <pages>
  571. <page3_3_1>
  572. <label>Page 3.3.1</label>
  573. <uri>page3/page3_3/page3_3_1</uri>
  574. <visible>0</visible>
  575. </page3_3_1>
  576. <page3_3_2>
  577. <label>Page 3.3.2</label>
  578. <uri>page3/page3_3/page3_3_2</uri>
  579. <resource>admin</resource>
  580. </page3_3_2>
  581. </pages>
  582. </page3_3>
  583. </pages>
  584. </page3>
  585. <home>
  586. <label>Home</label>
  587. <order>-100</order>
  588. <module>default</module>
  589. <controller>index</controller>
  590. <action>index</action>
  591. </home>
  592. </nav>
  593. </config>
  594. ]]></programlisting>
  595. <programlisting language="php"><![CDATA[
  596. $config = new Zend_Config_Xml('/path/to/navigation.xml', 'nav');
  597. $container = new Zend_Navigation($config);
  598. ]]></programlisting>
  599. <para>
  600. Example for YAML:
  601. </para>
  602. <programlisting language="yaml"><![CDATA[
  603. nav:
  604. zend:
  605. label: Zend
  606. uri: http://www.zend-project.com/
  607. order: 100
  608. page1:
  609. label: Page 1
  610. uri: page1
  611. pages:
  612. page1_1:
  613. label: Page 1.1
  614. uri: page1/page1_1
  615. page2:
  616. label: Page 2
  617. uri: page2
  618. pages:
  619. page2_1:
  620. label: Page 2.1
  621. uri: page2/page2_1
  622. page2_2:
  623. label: Page 2.2
  624. uri: page2/page2_2
  625. pages:
  626. page2_2_1:
  627. label: Page 2.2.1
  628. uri: page2/page2_2/page2_2_1
  629. page2_2_2:
  630. label: Page 2.2.2
  631. uri: page2/page2_2/page2_2_2
  632. active: 1
  633. page2_3:
  634. label: Page 2.3
  635. uri: page2/page2_3
  636. pages:
  637. page2_3_1:
  638. label: Page 2.3.1
  639. uri: page2/page2_3/page2_3_1
  640. page2_3_2:
  641. label: Page 2.3.2
  642. uri: page2/page2_3/page2_3_2
  643. visible: 0
  644. pages:
  645. page2_3_2_1:
  646. label: Page 2.3.2.1
  647. uri: page2/page2_3/page2_3_2/1
  648. active: 1
  649. page2_3_2_2:
  650. label: Page 2.3.2.2
  651. uri: page2/page2_3/page2_3_2/2
  652. active: 1
  653. pages:
  654. page_2_3_2_2_1:
  655. label: Ignore
  656. uri: #
  657. active: 1
  658. page2_3_3:
  659. label: Page 2.3.3
  660. uri: page2/page2_3/page2_3_3
  661. resource: admin
  662. pages:
  663. page2_3_3_1:
  664. label: Page 2.3.3.1
  665. uri: page2/page2_3/page2_3_3/1
  666. active: 1
  667. page2_3_3_2:
  668. label: Page 2.3.3.2
  669. uri: page2/page2_3/page2_3_3/2
  670. resource: guest
  671. active: 1
  672. page3:
  673. label: Page 3
  674. uri: page3
  675. pages:
  676. page3_1:
  677. label: Page 3.1
  678. uri: page3/page3_1
  679. resource: guest
  680. page3_2:
  681. label: Page 3.2
  682. uri: page3/page3_2
  683. resource: member
  684. pages:
  685. page3_2_1:
  686. label: Page 3.2.1
  687. uri: page3/page3_2/page3_2_1
  688. page3_2_2:
  689. label: Page 3.2.2
  690. uri: page3/page3_2/page3_2_2
  691. resource: admin
  692. page3_3:
  693. label: Page 3.3
  694. uri: page3/page3_3
  695. resource: special
  696. pages:
  697. page3_3_1:
  698. label: Page 3.3.1
  699. uri: page3/page3_3/page3_3_1
  700. visible: 0
  701. page3_3_2:
  702. label: Page 3.3.2
  703. uri: page3/page3_3/page3_3_2
  704. resource: admin
  705. home:
  706. label: Home
  707. order: -100
  708. module: default
  709. controller: index
  710. action: index
  711. ]]></programlisting>
  712. <programlisting language="php"><![CDATA[
  713. $config = new Zend_Config_Yaml'/path/to/navigation.yaml', 'nav');
  714. $container = new Zend_Navigation($config);
  715. ]]></programlisting>
  716. </example>
  717. </sect2>
  718. <sect2 id="zend.navigation.containers.adding">
  719. <title>Adding pages</title>
  720. <para>
  721. Adding pages to a container can be done with the methods
  722. <methodname>addPage()</methodname>, <methodname>addPages()</methodname>, or
  723. <methodname>setPages()</methodname>. See examples below for explanation.
  724. </para>
  725. <example id="zend.navigation.containers.adding.example">
  726. <title>Adding pages to a container</title>
  727. <programlisting language="php"><![CDATA[
  728. // create container
  729. $container = new Zend_Navigation();
  730. // add page by giving a page instance
  731. $container->addPage(Zend_Navigation_Page::factory(array(
  732. 'uri' => 'http://www.example.com/',
  733. )));
  734. // add page by giving an array
  735. $container->addPage(array(
  736. 'uri' => 'http://www.example.com/',
  737. ));
  738. // add page by giving a config object
  739. $container->addPage(new Zend_Config(array(
  740. 'uri' => 'http://www.example.com/',
  741. )));
  742. $pages = array(
  743. array(
  744. 'label' => 'Save',
  745. 'action' => 'save',
  746. ),
  747. array(
  748. 'label' => 'Delete',
  749. 'action' => 'delete',
  750. ),
  751. );
  752. // add two pages
  753. $container->addPages($pages);
  754. // add container
  755. $container->addPages(new Zend_Navigation(array(
  756. array(
  757. 'label' => 'Move up',
  758. 'action' => 'up',
  759. ),
  760. array(
  761. 'label' => 'Move down',
  762. 'action' => 'down',
  763. ),
  764. )));
  765. // remove existing pages and add the given pages
  766. $container->setPages($pages);
  767. ]]></programlisting>
  768. </example>
  769. </sect2>
  770. <sect2 id="zend.navigation.containers.removing">
  771. <title>Removing pages</title>
  772. <para>
  773. Removing pages can be done with <methodname>removePage()</methodname> or
  774. <methodname>removePages()</methodname>. The first method accepts a an instance
  775. of a page, or an integer. The integer corresponds to the
  776. <property>order</property> a page has. The latter method will remove all
  777. pages in the container.
  778. </para>
  779. <example id="zend.navigation.containers.removing.example">
  780. <title>Removing pages from a container</title>
  781. <programlisting language="php"><![CDATA[
  782. $container = new Zend_Navigation(array(
  783. array(
  784. 'label' => 'Page 1',
  785. 'action' => 'page1'
  786. ),
  787. array(
  788. 'label' => 'Page 2',
  789. 'action' => 'page2',
  790. 'order' => 200
  791. ),
  792. array(
  793. 'label' => 'Page 3',
  794. 'action' => 'page3'
  795. )
  796. ));
  797. // remove page by implicit page order
  798. $container->removePage(0); // removes Page 1
  799. // remove page by instance
  800. $page3 = $container->findOneByAction('page3');
  801. $container->removePage($page3); // removes Page 3
  802. // remove page by explicit page order
  803. $container->removePage(200); // removes Page 2
  804. // remove all pages
  805. $container->removePages(); // removes all pages
  806. ]]></programlisting>
  807. </example>
  808. </sect2>
  809. <sect2 id="zend.navigation.containers.finding">
  810. <title>Finding pages</title>
  811. <para>
  812. Containers have finder methods for retrieving pages.
  813. They are <methodname>findOneBy($property, $value, $useRegex = false)</methodname>,
  814. <methodname>findAllBy($property, $value, $useRegex = false)</methodname>, and
  815. <methodname>findBy($property, $value, $all = false, $useRegex = false)</methodname>.
  816. Those methods will recursively search the container for
  817. pages matching the given <command>$page->$property == $value</command>
  818. or when regular expressions are used:
  819. <command>preg_match($value, $page->$property)</command>.
  820. The first method, <methodname>findOneBy()</methodname>, will return a
  821. single page matching the property with the given value, or
  822. <constant>NULL</constant> if it cannot be found. The second method will return
  823. all pages with a property matching the given value. The third
  824. method will call one of the two former methods depending on the
  825. <varname>$all</varname> flag.
  826. </para>
  827. <para>
  828. The finder methods can also be used magically by appending the
  829. property name to <property>findBy</property>, <property>findOneBy</property>, or
  830. <property>findAllBy</property>, e.g. <methodname>findOneByLabel('Home')</methodname> to
  831. return the first matching page with label 'Home'.
  832. Other combinations are <methodname>findByLabel(...)</methodname>,
  833. <methodname>findOnyByTitle(...)</methodname>,
  834. <methodname>findAllByController(...)</methodname>, etc. Finder
  835. methods also work on custom properties, such as
  836. <methodname>findByFoo('bar')</methodname>.
  837. </para>
  838. <example id="zend.navigation.containers.finding.example">
  839. <title>Finding pages in a container</title>
  840. <programlisting language="php"><![CDATA[
  841. $container = new Zend_Navigation(array(
  842. array(
  843. 'label' => 'Page 1',
  844. 'uri' => 'page-1',
  845. 'foo' => 'bar',
  846. 'pages' => array(
  847. array(
  848. 'label' => 'Page 1.1',
  849. 'uri' => 'page-1.1',
  850. 'foo' => 'bar',
  851. ),
  852. array(
  853. 'label' => 'Page 1.2',
  854. 'uri' => 'page-1.2',
  855. 'class' => 'my-class',
  856. ),
  857. array(
  858. 'type' => 'uri',
  859. 'label' => 'Page 1.3',
  860. 'uri' => 'page-1.3',
  861. 'action' => 'about'
  862. )
  863. )
  864. ),
  865. array(
  866. 'label' => 'Page 2',
  867. 'id' => 'page_2_and_3',
  868. 'class' => 'my-class',
  869. 'module' => 'page2',
  870. 'controller' => 'index',
  871. 'action' => 'page1'
  872. ),
  873. array(
  874. 'label' => 'Page 3',
  875. 'id' => 'page_2_and_3',
  876. 'module' => 'page3',
  877. 'controller' => 'index'
  878. )
  879. ));
  880. // The 'id' is not required to be unique, but be aware that
  881. // having two pages with the same id will render the same id attribute
  882. // in menus and breadcrumbs.
  883. $found = $container->findBy('id', 'page_2_and_3'); // returns Page 2
  884. $found = $container->findOneBy('id', 'page_2_and_3'); // returns Page 2
  885. $found = $container->findBy('id', 'page_2_and_3', true); // returns Page 2 and Page 3
  886. $found = $container->findById('page_2_and_3'); // returns Page 2
  887. $found = $container->findOneById('page_2_and_3'); // returns Page 2
  888. $found = $container->findAllById('page_2_and_3'); // returns Page 2 and Page 3
  889. // Find all matching CSS class my-class
  890. $found = $container->findAllBy('class', 'my-class'); // returns Page 1.2 and Page 2
  891. $found = $container->findAllByClass('my-class'); // returns Page 1.2 and Page 2
  892. // Find first matching CSS class my-class
  893. $found = $container->findOneByClass('my-class'); // returns Page 1.2
  894. // Find all matching CSS class non-existant
  895. $found = $container->findAllByClass('non-existant'); // returns array()
  896. // Find first matching CSS class non-existant
  897. $found = $container->findOneByClass('non-existant'); // returns null
  898. // Find all pages with custom property 'foo' = 'bar'
  899. $found = $container->findAllBy('foo', 'bar'); // returns Page 1 and Page 1.1
  900. // To achieve the same magically, 'foo' must be in lowercase.
  901. // This is because 'foo' is a custom property, and thus the
  902. // property name is not normalized to 'Foo'
  903. $found = $container->findAllByfoo('bar');
  904. // Find all with controller = 'index'
  905. $found = $container->findAllByController('index'); // returns Page 2 and Page 3
  906. ]]></programlisting>
  907. <para>
  908. Use regular expressions to find pages:
  909. </para>
  910. <programlisting language="php"><![CDATA[
  911. $found = $container->findBy('class','/my/', false, true); // returns Page 1.2
  912. $found = $container->findOneBy('class', '/my/', true); // returns Page 1.2
  913. $found = $container->findBy('class', '/my/', true, true); // returns Page 1.2 and Page 2
  914. $found = $container->findAllBy('class', '/my/', true); // returns Page 1.2 and Page 2
  915. $found = $container->findOneByClass('/my/', true); // returns Page 1.2
  916. $found = $container->findAllByClass('/my/', true); // returns Page 1.2 and Page 2
  917. ]]></programlisting>
  918. </example>
  919. </sect2>
  920. <sect2 id="zend.navigation.containers.iterating">
  921. <title>Iterating containers</title>
  922. <para>
  923. <classname>Zend_Navigation_Container</classname> implements
  924. <classname>RecursiveIteratorIterator</classname>, and can be
  925. iterated using any <classname>Iterator</classname> class. To iterate
  926. a container recursively, use the
  927. <classname>RecursiveIteratorIterator</classname> class.
  928. </para>
  929. <example id="zend.navigation.containers.iterating.example">
  930. <title>Iterating a container</title>
  931. <programlisting language="php"><![CDATA[
  932. /*
  933. * Create a container from an array
  934. */
  935. $container = new Zend_Navigation(array(
  936. array(
  937. 'label' => 'Page 1',
  938. 'uri' => '#'
  939. ),
  940. array(
  941. 'label' => 'Page 2',
  942. 'uri' => '#',
  943. 'pages' => array(
  944. array(
  945. 'label' => 'Page 2.1',
  946. 'uri' => '#'
  947. ),
  948. array(
  949. 'label' => 'Page 2.2',
  950. 'uri' => '#'
  951. )
  952. )
  953. ),
  954. array(
  955. 'label' => 'Page 3',
  956. 'uri' => '#'
  957. )
  958. ));
  959. // Iterate flat using regular foreach:
  960. // Output: Page 1, Page 2, Page 3
  961. foreach ($container as $page) {
  962. echo $page->label;
  963. }
  964. // Iterate recursively using RecursiveIteratorIterator
  965. $it = new RecursiveIteratorIterator(
  966. $container, RecursiveIteratorIterator::SELF_FIRST);
  967. // Output: Page 1, Page 2, Page 2.1, Page 2.2, Page 3
  968. foreach ($it as $page) {
  969. echo $page->label;
  970. }
  971. ]]></programlisting>
  972. </example>
  973. </sect2>
  974. <sect2 id="zend.navigation.containers.other">
  975. <title>Other operations</title>
  976. <para>
  977. The method <methodname>hasPage(Zend_Navigation_Page $page)</methodname> checks
  978. if the container has the given page. The method <methodname>hasPages()</methodname>
  979. checks if there are any pages in the container, and is equivalent
  980. to <command>count($container) > 1</command>.
  981. </para>
  982. <para>
  983. The <methodname>toArray()</methodname> method converts the container and the
  984. pages in it to an array. This can be useful for serializing and
  985. debugging.
  986. </para>
  987. <example id="zend.navigation.containers.other.example.toarray">
  988. <title>Converting a container to an array</title>
  989. <programlisting language="php"><![CDATA[
  990. $container = new Zend_Navigation(array(
  991. array(
  992. 'label' => 'Page 1',
  993. 'uri' => '#'
  994. ),
  995. array(
  996. 'label' => 'Page 2',
  997. 'uri' => '#',
  998. 'pages' => array(
  999. array(
  1000. 'label' => 'Page 2.1',
  1001. 'uri' => '#'
  1002. ),
  1003. array(
  1004. 'label' => 'Page 2.2',
  1005. 'uri' => '#'
  1006. )
  1007. )
  1008. )
  1009. ));
  1010. var_dump($container->toArray());
  1011. /* Output:
  1012. array(2) {
  1013. [0]=> array(15) {
  1014. ["label"]=> string(6) "Page 1"
  1015. ["id"]=> NULL
  1016. ["class"]=> NULL
  1017. ["title"]=> NULL
  1018. ["target"]=> NULL
  1019. ["rel"]=> array(0) {
  1020. }
  1021. ["rev"]=> array(0) {
  1022. }
  1023. ["order"]=> NULL
  1024. ["resource"]=> NULL
  1025. ["privilege"]=> NULL
  1026. ["active"]=> bool(false)
  1027. ["visible"]=> bool(true)
  1028. ["type"]=> string(23) "Zend_Navigation_Page_Uri"
  1029. ["pages"]=> array(0) {
  1030. }
  1031. ["uri"]=> string(1) "#"
  1032. }
  1033. [1]=> array(15) {
  1034. ["label"]=> string(6) "Page 2"
  1035. ["id"]=> NULL
  1036. ["class"]=> NULL
  1037. ["title"]=> NULL
  1038. ["target"]=> NULL
  1039. ["rel"]=> array(0) {
  1040. }
  1041. ["rev"]=> array(0) {
  1042. }
  1043. ["order"]=> NULL
  1044. ["resource"]=> NULL
  1045. ["privilege"]=> NULL
  1046. ["active"]=> bool(false)
  1047. ["visible"]=> bool(true)
  1048. ["type"]=> string(23) "Zend_Navigation_Page_Uri"
  1049. ["pages"]=> array(2) {
  1050. [0]=> array(15) {
  1051. ["label"]=> string(8) "Page 2.1"
  1052. ["id"]=> NULL
  1053. ["class"]=> NULL
  1054. ["title"]=> NULL
  1055. ["target"]=> NULL
  1056. ["rel"]=> array(0) {
  1057. }
  1058. ["rev"]=> array(0) {
  1059. }
  1060. ["order"]=> NULL
  1061. ["resource"]=> NULL
  1062. ["privilege"]=> NULL
  1063. ["active"]=> bool(false)
  1064. ["visible"]=> bool(true)
  1065. ["type"]=> string(23) "Zend_Navigation_Page_Uri"
  1066. ["pages"]=> array(0) {
  1067. }
  1068. ["uri"]=> string(1) "#"
  1069. }
  1070. [1]=>
  1071. array(15) {
  1072. ["label"]=> string(8) "Page 2.2"
  1073. ["id"]=> NULL
  1074. ["class"]=> NULL
  1075. ["title"]=> NULL
  1076. ["target"]=> NULL
  1077. ["rel"]=> array(0) {
  1078. }
  1079. ["rev"]=> array(0) {
  1080. }
  1081. ["order"]=> NULL
  1082. ["resource"]=> NULL
  1083. ["privilege"]=> NULL
  1084. ["active"]=> bool(false)
  1085. ["visible"]=> bool(true)
  1086. ["type"]=> string(23) "Zend_Navigation_Page_Uri"
  1087. ["pages"]=> array(0) {
  1088. }
  1089. ["uri"]=> string(1) "#"
  1090. }
  1091. }
  1092. ["uri"]=> string(1) "#"
  1093. }
  1094. }
  1095. */
  1096. ]]></programlisting>
  1097. </example>
  1098. </sect2>
  1099. </sect1>