Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [ZF] $this->_redirect
toomeczek
post
Post #1





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 7.03.2007
Skąd: Mszczonów

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


Mam plugin który wykonuje sie przed Dispatcherem i sprawdza czy użytkownik jest zalogowany. Jak nie jest zalogowany to powinien przekierować do panelu logowania, tylko nie wiem jak sie odwołać do _redirect(''), bo $this dowoluje sie do Zend_Controller_Plugin_Abstract, a tu nie ma tej metody. Macie jakiś pomysł?

  1. <?php
  2. class Zend_Controller_Plugin_Authorization extends Zend_Controller_Plugin_Abstract
  3. {
  4. public function preDispatch(Zend_Controller_Request_Abstract $request)
  5. {
  6. $name = $this->getRequest()->getControllerName();
  7. $auth = Zend_Auth::getInstance();
  8.  
  9. if(!$auth->hasIdentity() and $name!='admin')
  10. {  
  11.  $this->_redirect('/admin'); //niezalogowany
  12. }
  13. }
  14. }
  15. ?>


Zmieniłem na coś takiego
  1. <?php
  2. if(!$auth->hasIdentity() and $name!='admin')
  3. {  
  4.  $this->getRequest()->setControllerName('admin');
  5. }
  6. ?>


Ten post edytował toomeczek 26.06.2008, 11:37:13
Go to the top of the page
+Quote Post
batman
post
Post #2





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




_redirect jest helperem widoku, więc musisz mieć instancję widoku. Jak ją wyciągniesz, to już zależy od Ciebie, sposobów jest kilka. Ale zamiast kombinować z _redirect możesz zrobić coś takiego:
  1. <?php
  2. $response = $this->getResponse();
  3. $response->setRedirect('/error/access/');
  4. $response->sendHeaders();
  5. ?>


--------------------
I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features.
Go to the top of the page
+Quote Post
toomeczek
post
Post #3





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 7.03.2007
Skąd: Mszczonów

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


OK, dziala smile.gif


Mam jeszcze jedno pytanie bo zrobilem odrazu:

  1. <?php
  2. public function Authentication($auth){
  3. $user=$auth->getIdentity();
  4. if($user){
  5.  
  6. $uprawnienia= $user->uprawnienia;
  7. $acl = new Zend_Acl();
  8. $acl->addRole(new Zend_Acl_Role('guest'))
  9. ->addRole(new Zend_Acl_Role('member'))
  10. ->addRole(new Zend_Acl_Role('admin'));
  11.  
  12. $acl->add(new Zend_Acl_Resource('index')); 
  13. $acl->allow('guest', 'index');
  14.  
  15. $acl->add(new Zend_Acl_Resource('admin')); 
  16. $acl->allow('guest', 'admin');
  17.  
  18. return $acl->isAllowed($uprawnienia, $this->name) ? '1' : '0';
  19.  
  20. }else return 1;
  21. }
  22. ?>


i tu jak zworci 0 to znacza ze nie ma dostepu, chce to wyswietlic uzytkownikowi,
ale
  1. <?php
  2. Zend_Loader::loadClass('Zend_View');
  3. $view = new Zend_View();
  4. $view->books = $data;
  5.  
  6. // and render a view script called "error.php"
  7. echo $view->render('booklist.php');
  8. ?>


nie dziala bo mam header i footer w folderze wyżej zeby byl dostepny dla wszystkich widokow i nie chce mi ich wczytac. Ustawiam
$view->setScriptPath('/application/views/script'); ale i tak nie dziala
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




Miałem podobny problem z dołączaniem menu i rozwiązałem to dodając poniższy kod do metody init() w kontrolerze
  1. <?php
  2. $this->view->addScriptPath('../application/modules/admin/views/scripts/');
  3. /* Twoj kod */
  4. $this->view->setScriptPath('../application/modules/documents/views/scripts/');
  5. ?>


--------------------
I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features.
Go to the top of the page
+Quote Post
toomeczek
post
Post #5





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 7.03.2007
Skąd: Mszczonów

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


No tak, ale w index.phtml mam takei cos:

  1. <?php echo $this->render('header.phtml'); ?>
  2. <?php echo $this->render('menu_up.phtml'); ?>
  3. <?php echo $this->render('footer.phtml'); ?>


i juz nie widzi tego bo jest poziom wyzej zeby bylo dostepny dla wszystkich
Go to the top of the page
+Quote Post
batman
post
Post #6





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




Zamiast bawić się takie coś, użyj Zend_Layout. Masz wtedy większą kontrolę nad wyglądem strony i nie musisz kombinować z widocznością.


--------------------
I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features.
Go to the top of the page
+Quote Post
toomeczek
post
Post #7





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 7.03.2007
Skąd: Mszczonów

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


Ok pobawiłem sie Zend_Layout i nawet doinstalowalem sobie Smarty, ale jak mam glowny plik layout.tpl, a akcje mam admin/login/ to i tak wczytuje mi tylko layout.tpl, jak zrobić zeby wczytywal mi odpowiadnia akcje?

bo nie wiem czy dobrze wczytuje:

  1. <?php
  2. Zend_Layout::startMvc(array('layoutPath' => $config->layout->layoutPath,
  3. 'view' => $view,
  4. 'contentKey' => $config->layout->contentKey,
  5. 'inflector' => $inflector));
  6. ?>


Ten post edytował toomeczek 27.06.2008, 09:58:49
Go to the top of the page
+Quote Post
batman
post
Post #8





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




W kontrolerze w metodzie init() ustawiasz jaki layout ma zostać wczytany
  1. <?php
  2. $layout->setLayout('nazwa_pliku_z_layoutem');
  3. ?>


--------------------
I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features.
Go to the top of the page
+Quote Post
toomeczek
post
Post #9





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 7.03.2007
Skąd: Mszczonów

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


OK tylko ze layouty mam wczytane w indeksie

  1. <?php
  2. $layout=Zend_Layout::startMvc(array('layoutPath' => $config->layout->layoutPath,
  3. 'view' => $view,
  4. 'contentKey' => $config->layout->contentKey,
  5. 'inflector' => $inflector));
  6. ?>


A nie w kontrolerach

Ok dałem sobie juz rade.

Ten post edytował toomeczek 27.06.2008, 10:13:49
Go to the top of the page
+Quote Post
batman
post
Post #10





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




Metoda setLayout() pozwala na podmianę aktualnego layoutu. Dzięki temu możesz dowolnie wczytywać layouty.


--------------------
I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features.
Go to the top of the page
+Quote Post
toomeczek
post
Post #11





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 7.03.2007
Skąd: Mszczonów

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


Tak tylko nie wiedzialem jak sie do niej odwołać ale zapomnialem o helperach:

  1. <?php
  2. $this->_helper->layout->setLayout
  3. ?>


Mam jeszcze jedno pytanie mam nadzieje ze ostatnie, bo po zalogowaniu przez Zend_Auth_Adapter_DbTable

chce w layoutach używające helpera pokazywać dane użytkownika zalogowanygo, np przy linku wyloguj, ale jak wczytuje helper

  1. <?php
  2. class Zend_View_Hepler_Admin{
  3.  
  4. function Admin(){
  5. $auth = Zend_Auth::getInstance();
  6. $user=$auth->getIdentity();
  7.  
  8. return $user;
  9. }
  10.  
  11. }
  12. ?>

który jest w katalogu application/views/helpers/

i wywoluje go w pliku phtml
  1. <?php
  2. $this->Admin();
  3. ?>


to dostaje bląd

  1. <?php
  2. exception 'Zend_View_Exception' with message 'helper 'Admin' not found in path' in /home/emadness/public_html/cms/library/Zend/View/Abstract.php:1004Stack trace:
  3. #0 /home/emadness/public_html/cms/library/Zend/View/Abstract.php(497): Zend_View_Abstract->_loadClass('helper', 'Admin')
  4. #1 /home/emadness/public_html/cms/library/Zend/View/Abstract.php(294): Zend_View_Abstract->getHelper('Admin')
  5. #2 [internal function]: Zend_View_Abstract->__call('Admin', Array)
  6. #3 /home/emadness/public_html/cms/application/views/scripts/header.phtml(19): Zend_View->Admin()
  7. #4 /home/emadness/public_html/cms/library/Zend/View.php(46): include('/home/emadness/...')
  8. #5 /home/emadness/public_html/cms/library/Zend/View/Abstract.php(769): Zend_View->_run('./application/v...')
  9. #6 /home/emadness/public_html/cms/application/views/scripts/index/index.phtml(1): Zend_View_Abstract->render('header.phtml')#
  10. /home/emadness/public_html/cms/library/Zend/View.php(46): include('/home/emadness/...')
  11. #8 /home/emadness/public_html/cms/library/Zend/View/Abstract.php(769): Zend_View->_run('./application/v...')
  12. #9 /home/emadness/public_html/cms/library/Zend/Controller/Action/Helper/ViewRenderer.php(895): Zend_View_Abstract->render('index/index.pht...')
  13. #10 /home/emadness/public_html/cms/library/Zend/Controller/Action/Helper/ViewRenderer.php(916): Zend_Controller_Action_Helper_ViewRenderer->renderScript('index/index.pht...', NULL)
  14. #11 /home/emadness/public_html/cms/library/Zend/Controller/Action/Helper/ViewRenderer.php(955): Zend_Controller_Action_Helper_ViewRenderer->render()
  15. #12 /home/emadness/public_html/cms/library/Zend/Controller/Action/HelperBroker.php(161): Zend_Controller_Action_Helper_ViewRenderer->postDispatch()
  16. #13 /home/emadness/public_html/cms/library/Zend/Controller/Action.php(512): Zend_Controller_Action_HelperBroker->notifyPostDispatch()
  17. #14 /home/emadness/public_html/cms/library/Zend/Controller/Dispatcher/Standard.php(293): Zend_Controller_Action->dispatch('indexAction')
  18. #15 /home/emadness/public_html/cms/library/Zend/Controller/Front.php(914): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
  19. #16 /home/emadness/public_html/cms/index.php(53): Zend_Controller_Front->dispatch()
  20. #17 {main}" exception 'Zend_View_Exception' with message 'helper 'Admin' not found in path' in /home/emadness/public_html/cms/library/Zend/View/Abstract.php:1004
  21.  Stack trace:
  22.  #0 /home/emadness/public_html/cms/library/Zend/View/Abstract.php(497): Zend_View_Abstract->_loadClass('helper', 'Admin')
  23.  #1 /home/emadness/public_html/cms/library/Zend/View/Abstract.php(294): Zend_View_Abstract->getHelper('Admin')
  24.  #2 [internal function]: Zend_View_Abstract->__call('Admin', Array)
  25.  #3 /home/emadness/public_html/cms/application/views/scripts/header.phtml(19): Zend_View->Admin()
  26.  #4 /home/emadness/public_html/cms/library/Zend/View.php(46): include('/home/emadness/...')
  27.  #5 /home/emadness/public_html/cms/library/Zend/View/Abstract.php(769): Zend_View->_run('./application/v...')
  28.  #6 /home/emadness/public_html/cms/application/views/scripts/index/index.phtml(1): Zend_View_Abstract->render('header.phtml')
  29.  #7 /home/emadness/public_html/cms/library/Zend/View.php(46): include('/home/emadness/...')
  30.  #8 /home/emadness/public_html/cms/library/Zend/View/Abstract.php(769): Zend_View->_run('./application/v...')
  31.  #9 /home/emadness/public_html/cms/library/Zend/Controller/Action/Helper/ViewRenderer.php(895): Zend_View_Abstract->render('index/index.pht...')
  32.  #10 /home/emadness/public_html/cms/library/Zend/Controller/Action/Helper/ViewRenderer.php(916): Zend_Controller_Action_Helper_ViewRenderer->renderScript('index/index.pht...', NULL)
  33.  #11 /home/emadness/public_html/cms/library/Zend/Controller/Action/Helper/ViewRenderer.php(955): Zend_Controller_Action_Helper_ViewRenderer->render()
  34.  #12 /home/emadness/public_html/cms/library/Zend/Controller/Action/HelperBroker.php(161): Zend_Controller_Action_Helper_ViewRenderer->postDispatch()
  35.  #13 /home/emadness/public_html/cms/library/Zend/Controller/Action.php(512): Zend_Controller_Action_HelperBroker->notifyPostDispatch()
  36.  #14 /home/emadness/public_html/cms/library/Zend/Controller/Dispatcher/Standard.php(293): Zend_Controller_Action->dispatch('indexAction')
  37.  #15 /home/emadness/public_html/cms/library/Zend/Controller/Front.php(914): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
  38.  #16 /home/emadness/public_html/cms/index.php(53): Zend_Controller_Front->dispatch()
  39.  #17 {main}
  40. ?>
Go to the top of the page
+Quote Post
batman
post
Post #12





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




Masz złe ścieżki. Jeśli Twój helper ma klasę Zend_View_Hepler_Admin, to w katalogu Zend/View/Helper musi się znaleźć plik Admin.php
A jeśli chcesz, by helper był tam, gdzie go zapisałeś, czyli application/views/helpers/, to klasa musi mieć postać Application_View_Helpers_Admin (ale głowy nie dam). A dodawanie ścieżek, w których można znaleźć helpera, robisz tak:
  1. <?php
  2. $view->addHelperPath('/path/to/some/helpers', 'My_View_Helper');
  3. ?>


--------------------
I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features.
Go to the top of the page
+Quote Post
toomeczek
post
Post #13





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 7.03.2007
Skąd: Mszczonów

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


Ok, tez osbie poradzilem ale bez sciezki.

A mam pytanie co do layoutow bo z automatu jest wczytywany layout.phtml nawet jak jest akcja admin/loguj/ i w kazdej akcji musze przypisywac jaki layout ma byc wykonany, troche to niepotrzebne tzn za kazdym razem musze pamietac o przypisaniu layoutu, da się włączyć to z automatu zeby sam wczytywał? Bo przeszukalem sporo i nie moge znalezc.
Go to the top of the page
+Quote Post
batman
post
Post #14





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




Z tego co sam szukałem, to nie znalazłem takiej możliwości. Jaki layout ma się wczytać ustawiam w metodzie init() kontrolera.


--------------------
I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features.
Go to the top of the page
+Quote Post
toomeczek
post
Post #15





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 7.03.2007
Skąd: Mszczonów

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


Jakos mi sie to nie podoba, bo jak mam struktura/add/ i struktura/edit/ chce do tego przypisac jeden layout item.phtml ale wywala mi odrazu blad ze brakuje add.phtml albo edit.phtml.
Go to the top of the page
+Quote Post
batman
post
Post #16





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




Ponieważ nie masz pliku widoku. Layout to tylko opakowanie plik widoku, dzięki czemu nie musisz w każdym widoku wklejać nagłówka, stopki, menu, itd.


--------------------
I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features.
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: 19.08.2025 - 16:04