Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [ZendFramework] Problem z przełączeniem kontrolera w pluginie, Zend_Controller_Plugin_Abstract i preDispatch()
Walian
post
Post #1





Grupa: Zarejestrowani
Postów: 124
Pomógł: 1
Dołączył: 13.07.2009

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


  1. <?php
  2. class My_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
  3. {
  4. public function preDispatch(Zend_Controller_Request_Abstract $request)
  5. {
  6. $acl = Zend_Registry::get('acl');
  7. $auth = Zend_Auth::getInstance();
  8. $identity = $auth->getIdentity();
  9. if (!$identity || (empty($identity->account_type)))
  10. $roleName = 'guest';
  11. else if ($identity->account_type == 1)
  12. $roleName = 'client';
  13. else if ($identity->account_type == 2)
  14. $roleName = 'vip';
  15. else if ($identity->account_type == 3)
  16. $roleName = 'admin';
  17.  
  18. $resourceName = $request->getControllerName();
  19. $privilegeName = $request->getActionName();
  20. if (!$acl->isAllowed($roleName, $resourceName, $privilegeName))
  21. {
  22. //$request->setControllerName('error');
  23. //$request->setActionName('index');
  24. }
  25. }
  26. }


Jeśli zmienię akcję, to jest OK, ale jak tylko przełączę na jakikolwiek kontroler (nawet "index" i akcja "index") to mam Internal Server Error. Chcę po prostu zablokować dostęp do pewnych stron - nie wiem czy tak powinienem to robić...
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
tomsol
post
Post #2





Grupa: Zarejestrowani
Postów: 36
Pomógł: 1
Dołączył: 15.01.2012

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


Może w kontroleze zrób cos takiego:

  1. public function init()
  2. {
  3. $auth = Zend_Auth::getInstance();
  4. if ($auth->hasIdentity())
  5. {
  6. $user = new Application_Model_User(); // tu metody co sprawdzają czy is guest ? i is user ?
  7. $this->view->zalogowany = $auth->hasIdentity();
  8. $this->view->identyfikator = $login = $auth->getIdentity();
  9.  
  10. if ($user->guest($login) || $user->client($login))
  11. {
  12. $this->access = true;
  13. }
  14. }
  15. else
  16. {
  17. return $this->_redirect('/get/out/...);
  18. }
  19. }
  20. // i tu w danej akcji dasz czy if(!$his->access){return $this->_redirect('/get/out/...);}
  21.  


dla danych roli blokujesz dostep dla danej akcji

chyba ze mozesz zablokowac dostep do wszystkich użyć htaccess ?

Ten post edytował tomsol 22.04.2012, 16:24:54
Go to the top of the page
+Quote Post
Walian
post
Post #3





Grupa: Zarejestrowani
Postów: 124
Pomógł: 1
Dołączył: 13.07.2009

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


Dzięki za rady, jak wrócę do tego problemu to dam znać czy to mi pomogło. Chociaż wolałbym rozwiązanie w pluginie, wydaje mi się rozsądniejsze.
Go to the top of the page
+Quote Post
batman
post
Post #4





Grupa: Moderatorzy
Postów: 2 921
Pomógł: 269
Dołączył: 11.08.2005
Skąd: 127.0.0.1




Wygląda na to, że dana rola nie ma uprawnień do kontrolera error i stąd ten problem.
Go to the top of the page
+Quote Post

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: 22.12.2025 - 21:21