繁体   English   中英

致命错误:在服务器中部署但不在本地部署时,在Zend Framework 2中找不到类

[英]Fatal error: Class not found in Zend Framework 2 when deployed in server but not locally

当我从本地主机使用应用程序时,它可以正常工作,但是当我在服务器中部署应用程序时,出现下一个错误:

致命错误:在第59行的/var/www/html/pfpdi/module/PFC/Module.php中找不到类'PFC \\ Model \\ GestoresPFC'

我正在使用具有下一个树结构的模块

  • PFC /
    • 配置/
    • src /
      • 控制器/
      • 形成/
      • 模型/
        • gestoresPFC.php
        • gestoresPFCTable.php
        • PFC.php
        • PFCTable.php
    • 视图/
    • autoload_classmap.php
    • Module.php

gestoresPFC.php类似于:

<?php 
 namespace PFC\Model;
 use Zend\InputFilter\InputFilter;
 use Zend\InputFilter\InputFilterAwareInterface;
 use Zend\InputFilter\InputFilterInterface;

 class GestoresPFC implements InputFilterAwareInterface
 {
     public $gestor_id;
     public $plan_id;
     protected $inputFilter;                       // <-- Add this variable

     public function exchangeArray($data)
     {
         $this->gestor_id  = (isset($data['gestor_id'])) ? $data['gestor_id']     : null;
         $this->plan_id     = (isset($data['plan_id']))     ? $data['plan_id']     : null;

     }

      public function getArrayCopy()
     {
         return get_object_vars($this);
     }

     // Add content to these methods:
     public function setInputFilter(InputFilterInterface $inputFilter)
     {
         throw new \Exception("Not used");
     }

    public function getInputFilter()
     {
         if (!$this->inputFilter) {
             $inputFilter = new InputFilter();


             $inputFilter->add(array(
                 'name'     => 'gestor_id',
                 'required' => true,
                 'filters'  => array(
                     array('name' => 'StripTags'),
                     array('name' => 'StringTrim'),
                 ),
                 'validators' => array(
                     array(
                         'name'    => 'StringLength',
                         'options' => array(
                             'encoding' => 'UTF-8',
                             'min'      => 1,
                             'max'      => 100,
                         ),
                     ),
                 ),
             ));

             $inputFilter->add(array(
                 'name'     => 'plan_id',
                 'required' => true,
                 'filters'  => array(
                     array('name' => 'StripTags'),
                     array('name' => 'StringTrim'),
                 ),
                 'validators' => array(
                     array(
                         'name'    => 'StringLength',
                         'options' => array(
                             'encoding' => 'UTF-8',
                             'min'      => 1,
                             'max'      => 11,
                         ),
                     ),
                 ),
             ));

             $this->inputFilter = $inputFilter;
         }

         return $this->inputFilter;
     }
 }

Module.php就像:

<?php
namespace PFC;

 use PFC\Model\PFC;
 use PFC\Model\PFCTable;
 use PFC\Model\GestoresPFC;
 use PFC\Model\GestoresPFCTable;
 use Zend\Db\ResultSet\ResultSet;
 use Zend\Db\TableGateway\TableGateway;
 use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
 use Zend\ModuleManager\Feature\ConfigProviderInterface;


 class Module implements AutoloaderProviderInterface, ConfigProviderInterface
 {
     public function getAutoloaderConfig()
     {
         return array(
             'Zend\Loader\ClassMapAutoloader' => array(
                 __DIR__ . '/autoload_classmap.php',
             ),
             'Zend\Loader\StandardAutoloader' => array(
                 'namespaces' => array(
                     __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                 ),
             ),
         );
     }

     public function getConfig()
     {
         return include __DIR__ . '/config/module.config.php';
     }


     public function getServiceConfig()
     {
         return array(
             'factories' => array(
                 'PFC\Model\PFCTable' =>  function($sm) {
                     $tableGateway = $sm->get('PFCTableGateway');
                     $table = new PFCTable($tableGateway);
                     return $table;
                 },
                 'PFCTableGateway' => function ($sm) {
                     $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                     $resultSetPrototype = new ResultSet();
                     $resultSetPrototype->setArrayObjectPrototype(new PFC());
                     return new TableGateway('plan_formacion', $dbAdapter, null, $resultSetPrototype);
                 },
                 'PFC\Model\GestoresPFCTable' =>  function($sm) {
                     $tableGateway = $sm->get('GestoresPFCTableGateway');
                     $table = new GestoresPFCTable($tableGateway);
                     return $table;
                 },
                 'GestoresPFCTableGateway' => function ($sm) {
                     $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                     $resultSetPrototype = new ResultSet();
                     $resultSetPrototype->setArrayObjectPrototype(new GestoresPFC());
                     return new TableGateway('gestores', $dbAdapter, null, $resultSetPrototype);
                 },

             ),
         );
     }

 }

gestoresPFC.php应该是GestoresPFC.php 文件名需要与类名匹配。 我猜您是在不区分大小写的文件系统(例如Windows)上开发此站点的,这无关紧要。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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