Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [ZendFramework] layout i zend_form
kociupk
post
Post #1





Grupa: Zarejestrowani
Postów: 97
Pomógł: 1
Dołączył: 29.03.2006

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


zastanawiam sie jak przekazac formularz do layout, odebrac dane i sprawdzic czu uzytkownik jest zalogowany

mam plik indexController ktory przekazuje formularz do helpera
  1. class IndexController extends Zend_Controller_Action
  2. {
  3. function init()
  4. {
  5. $form = new App_Form_Login();
  6. $helper= $this->_helper->getHelper('formlogin');
  7. $helper->formlogin($form);
  8. }
  9. }

plik helper FormLogin

  1. class Zend_View_Helper_FormLogin extends Zend_View_Helper_Abstract
  2. {
  3. private $form;
  4.  
  5. public function formlogin($form)
  6. {
  7. return $form;
  8. }
  9. }

plik bootstrap
  1. protected function _initViewHelper()
  2. {
  3. $this->bootstrap('layout');
  4. $layout = $this->getResource('layout');
  5. $view = $layout->getView();
  6.  
  7. $form = new Zend_View_Helper_FormLogin();
  8. $view = $form->formlogin();
  9. }

nie wiem czy to dziala wszystko pisane z palca chce sie dowiedziec czy mam dobry tok myslenia czy to tak ma mniej wiecej wygladac

Ten post edytował kociupk 10.04.2010, 14:18:51
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
webmaniak
post
Post #2





Grupa: Zarejestrowani
Postów: 371
Pomógł: 30
Dołączył: 14.04.2010

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


Witam, mam podobny problem co założyciel tematu. Mianowicie chciałbym po prawej stronie w layoucie stworzyć panel logowania więc w layoucie jest np.:
  1. <?php echo $this->layout()->panel; ?>

Z tego co dowiedziałem z innych źródeł muszę stworzyć akcję panel w indexController, więc:
  1. //panelAction() w pliku indexController.php:
  2. public function panelAction()
  3. {
  4. $form = new Application_Form_Panel();
  5. $request = $this->getRequest();
  6.  
  7. if ($request->isPost()) {
  8. if ($form->isValid($request->getPost())) {
  9.  
  10. $user = new Application_Model_User();
  11. $user->login = $form->getValue('login');
  12. $user->password = $form->getValue('password');
  13. $result = Zend_Auth::getInstance()->authenticate($user);
  14.  
  15. if ($result->isValid()) {
  16. $this->_helper->redirector('index');
  17. } else {
  18. $form->login->addError('Podano niepoprawny login i/lub hasĹ?o.');
  19. }
  20. }
  21. }
  22.  
  23. $this->view->panelForm = $form;
  24. }


a plik z formularzem wygląda tak:
  1. <?php
  2. //plik Panel.php w folderze forms
  3. class Application_Form_Panel extends Zend_Form
  4. {
  5.  
  6. public function init()
  7. {
  8. $this->addElement('text', 'login', array(
  9. 'filters' => array(
  10. 'StringTrim'
  11. ),
  12. 'label' => 'Login:'
  13. ));
  14. $this->addElement('password', 'password', array(
  15. 'label' => 'Hasło:'
  16. ));
  17. $this->addElement('submit', 'submit', array(
  18. 'ignore' => true,
  19. 'label' => 'Zaloguj'
  20. ));
  21. }
  22.  
  23.  
  24. }


No i jeszcze plik panel.phtml:
  1. //plik panel.phtml w folderze views/scripts/index:
  2. <h1>Logowanie</h1>
  3.  
  4. <?php echo $this->panelForm ?>

Nie wiem co tu jest nie tak, będę wdzięczny za każdą wskazówkę.
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: 8.10.2025 - 08:51