Here is my
forms/LoginForm.php
<?php
class Form_Login extends Zend_Form
{
public function init()
{
$this->setMethod('post');
$this->setAction('/admin/login');
$this->setName('login');
$userid = new Zend_Form_Element_Text('userid');
$userid->setLabel('User ID')
->setRequired(true)
->addValidator('NotEmpty');
$password = new Zend_Form_Element_Password('password');
$password->setLabel('Password')
->setRequired(true)
->addValidator('NotEmpty');
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Login');
$this->addElements(array($userid, $password, $submit));
}
}
So in my controller I had to do
require_once '../application/forms/LoginForm.php';
$form = new Form_Login();
How should I adjust?
Thanks
-Tom
On Sun, 2008-09-28 at 17:38 -0700, Jeremy Brown wrote:
> From what you have provided it looks like you need to name things a little differently.
>
> You say that you have your forms in the application/forms directory, but then you call your form with a new Form_Login(). When using the autoloader, the underscore gets replaced with the server/system directory separator, meaning it's looking in application/form, not application/forms (note the plural of "form"). Either rename your folder or change the value in the calling code.
>
> In addition to this, you indicate via your require_once call that your file name is LoginForm.php. Assuming you've made the previous naming change, either your file name should be just Login.php or you need to rename your class to be Forms_LoginForm. This is because the autoloader reads the name of the class you are instantiating, and gets the path and file name from it. In this case, Forms/Login.php. It then looks in this file for a class by the same name (Forms_Login) to instantiate.
>
>
>
> Jeremy Brown
> Senior Web Developer
> Spear One
> 972-661-6038
> jbrown@spearone.com
> ________________________________________
> From: Tom Printy [tprinty@mail.edisonave.net]
> Sent: Sunday, September 28, 2008 8:14 PM
> To: fw-mvc@lists.zend.com
> Subject: [fw-mvc] Zend Autoloader and forms
>
> Hello I have a question about zend form and the autoloader.
>
> I have created a directory application/forms to house all my forms
>
> However the AutoLoader cannot find the forms directory. I still have to
> do something like
>
> require_once '../application/forms/LoginForm.php';
> $form = new Form_Login();
>
>
> Is there a shortcut I can take so Autoloader can take care of this form
> me?
>
>
> Thanks
> -Tom Printy
没有评论:
发表评论