🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.php
Article #219724

[ZendFramewoek] Form nie działa

#219724
From: Przemek
Date: Wed, 15 Jul 2009 10:35
81 lines
3098 bytes
Żywcem wstawiony przykład ze strony:
http://framework.zend.com/manual/en/zend.f...ickstart.render
punkt: 23.2.6. Putting it together


AuthControler.php
===========================================	
<?php

class AuthController extends Zend_Controller_Action
{
    public function getForm()
    {
       $form = new Zend_Form();
        $form->setAction('/Auth/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'));
        return $form;
    }

    public function indexAction()
    {
        // render user/form.phtml
        $this->view->form = $this->getForm();
        $this->render('login');
    }

    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('login');
        }

        $values = $form->getValues();
        // now try and authenticate....
    }

}
?>


login.phtml
============================
	
<h2>Please login:</h2>
<?php echo $this->form ?>


Wynik działania:
Please login:

Catchable fatal error: Method Zend_Form::__toString() must return a 
string value in 
C:\xampp\htdocs\ims\application\views\scripts\Auth\login.phtml on line 2


O co to może chodzić. Żywcem wstawiony przykład.
Technical Details
Message-ID: <h3kbi1$7fp$1@atlantis.news.neostrada.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.onet.pl!newsfeed.neostrada.pl!atlantis.news.neostrada.pl!news.neostrada.pl!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.onet.pl!newsfeed.neostrada.pl!atlantis.news.neostrada.pl!news.neostrada.pl!not-for-mail
From: Przemek <phpsuse@gmail.com>
Newsgroups: pl.comp.lang.php
Subject: [ZendFramewoek] Form nie działa
Date: Wed, 15 Jul 2009 12:35:42 +0200
Organization: TP - http://www.tp.pl/
Lines: 82
Message-ID: <h3kbi1$7fp$1@atlantis.news.neostrada.pl>
NNTP-Posting-Host: 195.205.245.90
Mime-Version: 1.0
X-Trace: atlantis.news.neostrada.pl 1247654274 7673 195.205.245.90 (15 Jul 2009 10:37:54 GMT)
X-Complaints-To: usenet@news.neostrada.pl
NNTP-Posting-Date: Wed, 15 Jul 2009 10:37:54 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.22 (Windows/20090605)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit