Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [ZendFramework] uzywanie Zend_Form
Forum PHP.pl > Forum > PHP > Frameworki
phpsuse
Witam,
Czytam dokumentacje ZendFramewoka i nie bradzo rozumiem gdzie mam powstawiać pewne moduły aby formularz działał prawidłowo.

Na stronie:
http://framework.zend.com/manual/en/zend.f...quickstart.html
jest cały opis.
Dokładnie chodzi mi o punkt. : 23.2.6. Putting it together

Nie wiem w które pliki powstawiać kod.


1.
----------------------------------------------------
  1. <?php
  2. $form = new Zend_Form();
  3. $form->setAction('/user/login')
  4.     ->setMethod('post');
  5.  
  6. // Create and configure username element:
  7. $username = $form->createElement('text', 'username');
  8. $username->addValidator('alnum')
  9.         ->addValidator('regex', false, array('/^[a-z]+/'))
  10.         ->addValidator('stringLength', false, array(6, 20))
  11.         ->setRequired(true)
  12.         ->addFilter('StringToLower');
  13.  
  14. // Create and configure password element:
  15. $password = $form->createElement('password', 'password');
  16. $password->addValidator('StringLength', false, array(6))
  17.         ->setRequired(true);
  18.  
  19. // Add elements to form:
  20. $form->addElement($username)
  21.     ->addElement($password)
  22.     // use addElement() as a factory to create 'Login' button:
  23.     ->addElement('submit', 'login', array('label' => 'Login'));
  24. ?>


2. W controler
------------------------------------------------
  1. <?php
  2. class UserController extends Zend_Controller_Action
  3. {
  4.    public function getForm()
  5.    {
  6.        // create form as above
  7.        return $form;
  8.    }
  9.  
  10.    public function indexAction()
  11.    {
  12.        // render user/form.phtml
  13.        $this->view->form = $this->getForm();
  14.        $this->render('form');
  15.    }
  16.  
  17.    public function loginAction()
  18.    {
  19.        if (!$this->getRequest()->isPost()) {
  20.            return $this->_forward('index');
  21.        }
  22.        $form = $this->getForm();
  23.        if (!$form->isValid($_POST)) {
  24.            // Failed validation; redisplay form
  25.            $this->view->form = $form;
  26.            return $this->render('form');
  27.        }
  28.  
  29.        $values = $form->getValues();
  30.        // now try and authenticate....
  31.    }
  32. }
  33. ?>


3. w widok
---------------------------------------------
  1. <h2>Please login:</h2>
  2. <?php echo $this->form ?>





Punk 2 i 3 to wiem, ale nie wiem gdzie 1.

Korzystam z Zend Studio. W momencie dodawanie Controlera tworzy mi się automatycznie widok.
Ale punkt 1 prawdopodobnie bo tak mi sie wydaje wstawia sie do View Helper. Ale jaki Helper's Prefix i Helper's Name ?


Przemek
Spawnm
Proszę dać kod w bbcode i poprawić tytuł na bardziej sensowny.
blooregard
Kod nr. 1 dokładnie w tym miejscu:
Kod
// create form as above
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.