Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [ZendFramework] uzywanie Zend_Form
phpsuse
post 14.07.2009, 12:45:08
Post #1





Grupa: Zarejestrowani
Postów: 59
Pomógł: 0
Dołączył: 22.06.2008

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


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

Ten post edytował phpsuse 14.07.2009, 13:16:29
Go to the top of the page
+Quote Post
Spawnm
post 14.07.2009, 12:49:15
Post #2





Grupa: Moderatorzy
Postów: 4 069
Pomógł: 497
Dołączył: 11.05.2007
Skąd: Warszawa




Proszę dać kod w bbcode i poprawić tytuł na bardziej sensowny.
Go to the top of the page
+Quote Post
blooregard
post 14.07.2009, 13:28:29
Post #3


Newsman


Grupa: Moderatorzy
Postów: 2 033
Pomógł: 290
Dołączył: 21.12.2007
Skąd: Łódź




Kod nr. 1 dokładnie w tym miejscu:
Kod
// create form as above


--------------------
Life's simple... You make choices and don't look back...
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 Wersja Lo-Fi Aktualny czas: 7.07.2025 - 04:18