开发者

Why isn't my form working with my modules?

开发者 https://www.devze.com 2023-02-27 08:58 出处:网络
I have an auth module, and would like to keep a Login form in the forms folder in the module. I have my class named Auth_Form_Login and the code I use to instantiate it in auth\'s Index controller is:

I have an auth module, and would like to keep a Login form in the forms folder in the module. I have my class named Auth_Form_Login and the code I use to instantiate it in auth's Index controller is:

$loginForm开发者_StackOverflow中文版 = new Auth_Form_Login($_POST);

However, Zend is complaining that it can't find the class. What am I doing wrong?

Edit

My directory structure is like so:

application
    configs
    layouts
    modules
        auth
            controllers
            models
            views
                forms      <--- This is what I want to autoload from
        default
            controllers
            models
            views

library
public

Also, modules are set up correctly:

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.params.prefixDefaultModule = false


Seems like you're missing module bootstrap for Auth module:

application
     modules
         auth
             Bootstrap.php

Which might consist of this only line - just to make autoloading magic work:

class Auth_Bootstrap extends Zend_Application_Module_Bootstrap {}


You're doing everything right in your form initialisation. The autoloader simply doesn't know where to find it so you need to setup zend autoloader correctly.

I am not sure how you created your module based structure. I use the cli tool which configures everything.

So in my application.ini file I have:

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules = ''
resources.frontController.params.prefixDefaultModule = "1"

And in my Boostrap.php:

$modelLoader = new Zend_Application_Module_Autoloader ( 
                      array ('namespace' => '', 'basePath' 
                                         => APPLICATION_PATH . 
                                             '/modules/default' ) );

You also can setup the autoloader manually by registering your resources:

$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
    'basePath' => 'path/to/my/directory',
    'namespace' => 'Auth',
    'resourceType' => array(
       'form' => array(
            'path' => 'forms/'
            'namespace' => 'Form'
        )
        //...your code
     )
   )
);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号