views:

145

answers:

3

I've got some stuff I'm trying to do with ZF; I have a LoginController.php in application/controllers/ with class LoginController extends Zend_Controller_Action. Within it, I have the following:

public function getForm()
{
    return new LoginForm(array(
                'action' => '/login/process',
                'method' => 'post',
                ));
}

I have a LoginForm.php inside application/forms/ that has the following:

class LoginForm extends Zend_Form
{
+-- 38 lines: public function init()--------------------------------------------
}

Now, when I visit example.com/login, I get the following:

Fatal error: Class 'LoginForm' not found in /var/application/controllers/LoginController.php on line 7

My application.ini is the default...

What am I doing wrong?

A: 

Did you actually create a LoginForm class? Because it if you did it isnt on your include path.

prodigitalson
A: 

name LoginForm path_from_closest_include_path_LoginForm
Assuming you have there the file LoginForm.php (notice the capital letters).

Itay Moav
And if my include_path looks like:`string(107) "/var/application/../library:/var/library:.:/usr/share/php:/usr/share/pear"`?
gms8994
assuming the /var/application/forms/ is the dir, then forms_LoginForm
Itay Moav
I adjusted LoginForm.php to the following:`class forms_LoginForm extends Zend_Form`, and changed the code to call forms_LoginForm. I still get the same error :(
gms8994
when I am reading it again, I think you are not using an autoloader, or you haven't set it up correctly.
Itay Moav
I'm using the default project from a `zf.sh create project <project>`, so if that doesn't include an autoloader, then I don't either...
gms8994
+1  A: 

Check your bootstrap.php file. If you are using the standard autoloader in there, you will need to prefix your form classes with Form_

A basic autoloader declaration should look like something this:

$autoloader = new Zend_Application_Module_Autoloader(array(
        'namespace' => '',
        'basePath'  => dirname(__FILE__),
));

So if this is the case, your form class should be named Form_LoginForm()

Mark
I'm using the default project from a zf.sh create project <project>, so if that doesn't include an autoloader, then I don't either...Where should this go?
gms8994

related questions