简体   繁体   中英

Zend: Unable to access form in controller

First I created a project using Zend_Tool . Then created a controller AuthenticationController in default module.

Created Form in projectfolder/application/forms/Login.php

class Forms_Login extends Zend_Form {
    public function _construct() {
        // add elements
    }
}

Accessing Form in myproject/application/controllers/AuthenticationController.php

public function loginAction() {
   $this->view->form = new Form_Login();
}

I am getting following error:

Fatal error: Class 'Application_Forms_Login' not found in /var/www/student/application/controllers/AuthenticationController.php on line 19

How can I access it with same form class name without including this file in AuthenticationController??

May be I have to tell zend in Bootstrap.php about this but I wan unable to find a sample code.

Thanks

you should declare them in your bootstrap.php file like so:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initAutoload()
    {
        $autoLoader=Zend_Loader_Autoloader::getInstance();
        $resourceLoader=new Zend_Loader_Autoloader_Resource(array(
            'basePath'=>APPLICATION_PATH,
            'namespace'=>'',
            'resourceTypes'=>array(
                'form'=>array(
                    'path'=>'forms/',
                    'namespace'=>'Forms_'
                )                
            )

            ));


        $autoLoader->pushAutoloader($resourceLoader);




    }


}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM