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
wlamywacz
post
Post #2





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

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


Niestety dostaje komunikat:
Cytat
Catchable fatal error: Argument 1 passed to Zend_Layout::setView() must implement interface Zend_View_Interface, string given, called in E:\Serwer\Apache\Zend\library\Zend\Layout.php on line 240 and defined in E:\Serwer\Apache\Zend\library\Zend\Layout.php on line 496


Ok poradziłem sobie, parametr view w tablicy wywalał błąd. Zrobiłem to w ten sposób:
  1. <?php
  2. $frontController->registerPlugin(new ViewPlugin($config->layouts->toArray()));
  3. ?>

  1. <?php
  2. class ViewPlugin extends Zend_Controller_Plugin_Abstract
  3. {
  4.  
  5.    private $config;
  6.    
  7.    public function __construct($config) {
  8.    
  9.        $this->config = $config;
  10.    
  11.    }
  12.    
  13.    public function preDispatch(Zend_Controller_Request_Abstract $request) {
  14.    
  15.        $module = $request->getModuleName();
  16.            
  17.        if(!isset($this->config[$module])) {
  18.            
  19.            $array = array(
  20.            'layoutPath' => $this->config['default']['layoutPatch'],
  21.            'layout' => $this->config['default']['layout']
  22.            );
  23.            
  24.            $viewPatch = $this->config['default']['viewPatch'];
  25.            
  26.        } else {
  27.            
  28.            $array = array(
  29.            'layoutPath' => $this->config[$module]['layoutPatch'],
  30.            'layout' => $this->config[$module]['layout']
  31.            );
  32.            
  33.            $viewPatch = $this->config[$module]['viewPatch'];
  34.            
  35.        }    
  36.            
  37.        Zend_Layout::startMvc($array);
  38.            
  39.        $view = Zend_Layout::getMvcInstance()->getView();
  40.        $view->doctype('XHTML1_STRICT');
  41.        $view->addScriptPath($viewPatch);
  42.        
  43.    }
  44.    
  45. }
  46. ?>


Na moje potrzeby w zupełności wystarcza (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
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: 12.10.2025 - 14:14