Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [ZendFramework] Kontrolery, akcje itp.
wlamywacz
post
Post #1





Grupa: Zarejestrowani
Postów: 535
Pomógł: 27
Dołączył: 3.05.2005

Ostrzeżenie: (20%)
X----


Witam (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Mam pytanie odnośnie kontrolerów akcji itp. Problem polega na tym, iż będę miał adresy w stylu:
localhost/admin/categories/add/

Mój kontroler:
  1. <?php
  2. class AdminController extends Zend_Controller_Action    {
  3.  
  4.    public function init() {
  5.    
  6.        $this->_helper->layout->setLayout('workers-layout');
  7.        
  8.        $this->layout = new Zend_Layout();
  9.        $this->layout->title = "Panel administracyjny";
  10.        
  11.        $response = $this->getResponse();
  12.        $response->insert('menu', $this->view->render('menu-admin.phtml'));  
  13.        
  14.    }
  15.  
  16.    public function indexAction()  {
  17.    
  18.    }
  19.    
  20.    public function categoriesAction() {
  21.        
  22.        $categories = new Categories();
  23.        
  24.        $this->view->categories = $categories->getTree();
  25.        
  26.    }
  27. }
  28. ?>


I teraz w akcji categories musiałbym zrobić switcha żeby obsłużyć ten dodatkowy parametr. Czy jest jakiś sposób na rozwiązanie tego ?

Pozdrawiam
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
EarthCitizen
post
Post #2





Grupa: Zarejestrowani
Postów: 286
Pomógł: 70
Dołączył: 13.01.2009

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


Ja kwestię layoutu mam rozwiązaną w xmlu i działa to tak:

  1. <?xml version='1.0' encoding='utf-8' ?>
  2. <request-layouts>
  3.  
  4.    <module>
  5.        <controller>
  6.            <action>frontend/default</action>
  7.        </controller>
  8.    </module>
  9.  
  10.    <administrator>
  11.        <controller>
  12.            <action>backend/default</action>
  13.        </controller>
  14.        <user>
  15.            <login>backend/login</login>
  16.        </user>
  17.    </administrator>
  18.  
  19. </request-layouts>


Mam klasę Plugin_Controller, którą rejestruję do front controllera
  1. <?php
  2. $front->registerPlugin(new Plugin_Controller());
  3. ?>


a w tej klasie

  1. <?php
  2. public function routeShutdown(Zend_Controller_Request_Abstract $request)
  3.    {
  4.        $module     = $request->getModuleName();
  5.        $controller = $request->getControllerName();
  6.        $action     = $request->getActionName();
  7.  
  8.        try {
  9.            $requestLayout = new Zend_Config_Xml('request-layouts.xml', $module);
  10.        } catch (Exception $exception) {
  11.            $requestLayout = new Zend_Config_Xml('request-layouts.xml', 'module');
  12.        }
  13.  
  14.        if (isset($requestLayout->$controller->$action)) {
  15.            $layoutController = $controller;
  16.            $layoutAction     = $action;
  17.        } else {
  18.            $layoutController = 'controller';
  19.            $layoutAction     = 'action';
  20.        }
  21.  
  22.        $options = array(
  23.            'layout'     => $layoutName,
  24.            'layoutPath' =>
  25.            'view' =>
  26.        );
  27.  
  28.        $layout = Zend_Layout::startMvc($options);
  29.  
  30.    }
  31. ?>


W taki sposób mam domyślny layout dla wszystkich modułów, kontrolerów i akcji, ale też dla każdego modułu, kontrolera i akcji mogę sobie ustawić inny.
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 14.10.2025 - 09:42