doulan4371 2014-08-10 14:32
浏览 51
已采纳

在引导程序中配置自动加载器失败

I followed a tutorial just to get deeper in the form topic.

I built a Form class: application/forms/BugReportForm.php I added to my bootstrap.php (before it was unused)

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' => 'Form_',
            )
            ),
        ));
        //return it ao sthat istcan stored in the bootstrap
        return $autoLoader;
    }

I built also my forms/BugReportForm.php

My BugController.php looks like this:

<?php

class BugController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function submitAction()
    {
        $frmBugReport = new Form_BugReport();
        $frmBugReport = setAction('/bug/submit');
        $frmBugReport = setMethod('post');
        $this->view->form = $frmBugReport;
    }

my application.ini

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0

includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
phpSettings.date.timezone = "Europe/Berlin"

resources.db.adapter = PDO_MYSQL
resources.db.params.host = localhost
resources.db.params.username = root
resources.db.params.password = 
resources.db.params.dbname = TQM
resources.db.params.charset = "utf8"
resources.db.params.driver_options.1002 = "SET NAMES utf8"


resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"

resources.view.doctype = "XHTML1_STRICT"

I get this Error : Class 'Form_BugReportForm' not found in ....

What ist wrong, I think the bootstrap doesn´t work or the namespace ist not known?

Folderstructure Folderstructure

folder forms

and at the moment I don´t use virtual hosts.

errors after changing my class call in $frmBugReport = new Application_Form_BugReportForm();

fatal error output

hier for example another very small form

<?php
// Formular wird angezeigt bei neue Ebene 1 und editieren
class Application_Form_Hierarchie extends Zend_Form
{

    public function init()
    {
        $this->setName('Ebene1');
        $this->setAttrib('enctype', 'multipart/form-data');         //Formular wird für Dateiuploads verwendet
        $nr = new Zend_Form_Element_Hidden('nr');
        $nr->addFilter('Int');
        $ebene1 = new Zend_Form_Element_Text('ebene1');
            $ebene1->setLabel('Ebene1')
            ->setRequired(true)
            ->addFilter('StripTags')
            ->addFilter('StringTrim')
            ->addValidator('NotEmpty');




        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setAttrib('nr', 'submitbutton');
        $this->addElements(array($nr, $ebene1, $submit));       //, $imagepreview
    }

}

?>

and hier the action (add) from the Controller:

$form = new Application_Form_Hierarchie();

I tried the other posibility (it is from a book tutorial) to learn how to use own formclasses. I think I should give up with the turorial and go back to the simple way.

  • 写回答

1条回答 默认 最新

  • dqgxazo4483 2014-08-10 15:19
    关注

    The problem probably comes from the wrong class name specified in your application. Be sure to follow these rules while working with zend from and models, and you'll be fine :

    Bootstrap.php file:

    class Bootstrap extends Zend_Application_Bootstrap_Bootstrap{
    
           protected function _initAutoload(){
            $resourceLoader= new Zend_Application_Module_Autoloader(
                                         array(   
                                              'namespace' => '',   
                                              'basePath' => APPLICATION_PATH
                                              ));
           $resourceLoader->addResourceType('model', 'models/', 'Model');
           $resourceLoader->addResourceType('form', 'forms/', 'Form');   
           return $resourceLoader;
          }
     }
    

    Zend_Form directory and file names :

    1. The Default name space in zend framework for Zend_Form is Form and it will pointing to folder named as forms.
    2. Your form class name should start with namespace as Form_
    3. Create a file inside the forms directory as yourFormName.php . This will be your Form class file.
    4. Inside yourFormName.php create a class as Form_yourFormName.php

    yourFormName.php :

    class Form_yourFormName extends Zend_Form
      {
      public function init()
      {
          //your form codes goes here like creating form elements
      }
     }
    

    Then in your controller get a instance of your defined form class :

    class YourController extends Zend_Controller_Action
     {
    public function indexAction()
    {
       $form = new Form_yourFormName();
       $this->view->form = $form;
    }
    }
    

    EDIT : For your case it should be :

        $frmBugReport = new Form_BugReportForm();
    

    Not :

       $frmBugReport = new Form_BugReport();
    

    Hope this will help you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?