Article View: pl.comp.lang.php
Article #219711[ZendFramework] Form
From: Przemek
Date: Tue, 14 Jul 2009 06:00
Date: Tue, 14 Jul 2009 06:00
88 lines
3295 bytes
3295 bytes
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.form.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.
----------------------------------------------------
$form = new Zend_Form();
$form->setAction('/user/login')
->setMethod('post');
// Create and configure username element:
$username = $form->createElement('text', 'username');
$username->addValidator('alnum')
->addValidator('regex', false, array('/^[a-z]+/'))
->addValidator('stringLength', false, array(6, 20))
->setRequired(true)
->addFilter('StringToLower');
// Create and configure password element:
$password = $form->createElement('password', 'password');
$password->addValidator('StringLength', false, array(6))
->setRequired(true);
// Add elements to form:
$form->addElement($username)
->addElement($password)
// use addElement() as a factory to create 'Login' button:
->addElement('submit', 'login', array('label' => 'Login'));
2. W controler
------------------------------------------------
class UserController extends Zend_Controller_Action
{
public function getForm()
{
// create form as above
return $form;
}
public function indexAction()
{
// render user/form.phtml
$this->view->form = $this->getForm();
$this->render('form');
}
public function loginAction()
{
if (!$this->getRequest()->isPost()) {
return $this->_forward('index');
}
$form = $this->getForm();
if (!$form->isValid($_POST)) {
// Failed validation; redisplay form
$this->view->form = $form;
return $this->render('form');
}
$values = $form->getValues();
// now try and authenticate....
}
}
3. w widok
---------------------------------------------
<h2>Please login:</h2>
<?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
Technical Details
Message-ID:
<h3h71j$nj7$1@atlantis.news.neostrada.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.onet.pl!newsfeed.neostrada.pl!nemesis.news.neostrada.pl!atlantis.news.neostrada.pl!news.neostrada.pl!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.onet.pl!newsfeed.neostrada.pl!nemesis.news.neostrada.pl!atlantis.news.neostrada.pl!news.neostrada.pl!not-for-mail From: Przemek <phpsuse@gmail.com> Newsgroups: pl.comp.lang.php Subject: [ZendFramework] Form Date: Tue, 14 Jul 2009 08:00:13 +0200 Organization: TP - http://www.tp.pl/ Lines: 89 Message-ID: <h3h71j$nj7$1@atlantis.news.neostrada.pl> NNTP-Posting-Host: 195.205.245.90 Mime-Version: 1.0 X-Trace: atlantis.news.neostrada.pl 1247551347 24167 195.205.245.90 (14 Jul 2009 06:02:27 GMT) X-Complaints-To: usenet@news.neostrada.pl NNTP-Posting-Date: Tue, 14 Jul 2009 06:02:27 +0000 (UTC) User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit