Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [ZF] Zend_Navigation + Zend_Db_Table - helper, jak pobrać i wyświetlić menu z bazy
mitring
post
Post #1





Grupa: Zarejestrowani
Postów: 78
Pomógł: 1
Dołączył: 4.03.2006

Ostrzeżenie: (0%)
-----


Cześć jako początkujący napotykam same problemy tongue.gif

Stworzyłem sobie helpera:
  1. class Zend_View_Helper_NavigationMenu extends Zend_View_Helper_Abstract
  2. {
  3. public function navigationMenu()
  4. {
  5. $dbAdapter = Zend_Db_Table::getDefaultAdapter();
  6. $menuArray = $dbAdapter->fetchAll("SELECT * FROM menu");
  7.  
  8. $navContainer = new Zend_Navigation();
  9.  
  10. foreach ( $menuArray as $value )
  11. {
  12. $navContainer->addPage(
  13. Zend_Navigation_Page::factory( array(
  14. 'uri' => $value['url'],
  15. 'label' => $value['name']
  16. )
  17. )
  18. );
  19. }
  20.  
  21. return $navContainer;
  22. }
  23. }


Kompletnie nie wiem jak jak stworzyć menu przy pomocy Zend_Navigation w helperze i wyświetlić go... mogę prosić o pomoc. Kompletnie się zagubiłem czytając manual zenda

-- edit --
  1. <?php echo $this->navigation($this->navigationMenu())->menu(); ?>


Działa - wyświetla się ale czy jest to poprawne rozwiązanie czy można o jakoś łatwiej zrobić?

Ten post edytował mitring 27.05.2012, 17:31:31


--------------------
Warsztat: PHPStorm; Zend Server CE; Delphi 2010 Pro
Warsztat: NetBeans; WAMP; Delphi 2010 Pro
Work on: coś tam dłubię ;)
Go to the top of the page
+Quote Post
irmidjusz
post
Post #2





Grupa: Zarejestrowani
Postów: 279
Pomógł: 60
Dołączył: 25.02.2012

Ostrzeżenie: (0%)
-----


Każdy użyty w szablonie phtml view helper ma ustawiony aktualny obiekt Zend_View_Interface (dostępny jako $this->view w helperze), więc możesz to samo zrobić też w ten sposób:

  1. class Zend_View_Helper_NavigationMenu extends Zend_View_Helper_Abstract
  2. {
  3. public function navigationMenu()
  4. {
  5. $dbAdapter = Zend_Db_Table::getDefaultAdapter();
  6. $menuArray = $dbAdapter->fetchAll("SELECT * FROM menu");
  7.  
  8. $navContainer = new Zend_Navigation();
  9.  
  10. foreach ( $menuArray as $value )
  11. {
  12. $navContainer->addPage(
  13. Zend_Navigation_Page::factory( array(
  14. 'uri' => $value['url'],
  15. 'label' => $value['name']
  16. )
  17. )
  18. );
  19. }
  20.  
  21. return (string) $this->view->navigation($navContainer)->menu();
  22. }
  23. }


I wtedy wywołanie w phtml będzie takie:

  1. <?php echo $this->navigationMenu(); ?>

Go to the top of the page
+Quote Post
siuda
post
Post #3





Grupa: Zarejestrowani
Postów: 23
Pomógł: 0
Dołączył: 15.03.2012

Ostrzeżenie: (0%)
-----


Cześć,

Dzięki wielkie! Właśnie sam szukałem jak dodać dynamiczne menu z bazy do widoku, ale nadal nie wiem jak dodać style do tak stworzonego menu? Wiem, że można parametrem 'class', ale odnosić się to będzie tylko do pojedyńczego elementu, a nie całości.


Pozdrawiam,
Go to the top of the page
+Quote Post
mitring
post
Post #4





Grupa: Zarejestrowani
Postów: 78
Pomógł: 1
Dołączył: 4.03.2006

Ostrzeżenie: (0%)
-----


Aby zmienić całość <ul>
  1. ->menu()->setUlClass('')


Jeśli chodzi o elementy <li> to jak wspomniałeś class

Ten post edytował mitring 28.05.2012, 16:25:59


--------------------
Warsztat: PHPStorm; Zend Server CE; Delphi 2010 Pro
Warsztat: NetBeans; WAMP; Delphi 2010 Pro
Work on: coś tam dłubię ;)
Go to the top of the page
+Quote Post
siuda
post
Post #5





Grupa: Zarejestrowani
Postów: 23
Pomógł: 0
Dołączył: 15.03.2012

Ostrzeżenie: (0%)
-----


Dzięki bardzo. Jak rozumiem przy tworzeniu drugiego menu powinienem utworzyć nowy helper, czy mogę działać w obrębie jednego?
Go to the top of the page
+Quote Post
mitring
post
Post #6





Grupa: Zarejestrowani
Postów: 78
Pomógł: 1
Dołączył: 4.03.2006

Ostrzeżenie: (0%)
-----


Możesz korzystać z jednego, w helperze możesz podawać paramert jakie menu ma być wczytanie i tyle smile.gif


--------------------
Warsztat: PHPStorm; Zend Server CE; Delphi 2010 Pro
Warsztat: NetBeans; WAMP; Delphi 2010 Pro
Work on: coś tam dłubię ;)
Go to the top of the page
+Quote Post
Fluke
post
Post #7





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 20.09.2010
Skąd: Kraków

Ostrzeżenie: (0%)
-----


Masz:
  1. function nav($nav)
  2. {
  3.  
  4. //Pobierasz jakimś swoim sposobem nawigację po przez zmienną nav
  5. ...
  6. $this->view->navigation()->menu()->render($myNav);
  7. }


Pozdrawiam smile.gif
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 10:04