致命错误:在Zend框架2中找不到类

ara*_*ibi 2 php class zend-framework2

我陷入了zend框架,我是新手,试图实现一个网站只是为了学习它.所以我的网站是关于比萨饼的.当我尝试添加披萨时,在发送表单数据后,我收到此错误消息说:致命错误:在C:\ wamp\www\pizzalast\module\PizzaPoint\src\PizzaPoint中找不到类'PizzaPoint\Controller\Pizza'第27行的Controller\PizzaController.php,在这一行中,我实际上是一个位于"Model"文件夹中的类Pizza的对象.

这是披萨控制器的添加动作:

public function addAction()
    {
    $form = new PizzaForm();
    $form->get('submit')->setValue('Add');

    $request = $this->getRequest();
    if($request->isPost())
        {
        $pizza = new Pizza();
        $form->setInputFilter($pizza->getInputFilter());
        $form->setData($request->getPost());

            if($form->isValid())
                {
                    $pizza->exchangeArray($form->getData());
                    $this->getPizzaTable()->savePizza($pizza);
                }       
        }   
    return array('form' => $form);
    }
Run Code Online (Sandbox Code Playgroud)

这些是Pizza.php文件的前40行代码:

namespace PizzaPoint\Model;

use Zend\InputFilter\InputFilter;
use Zend\InputFilter\InputFilterAwareInterface;

use Zend\InputFilter\InputFilterInterface;

class Pizza implements InputFilterAwareInterface {

public $id;
public $title;
public $zutaten;
public $smallprice;
public $bigprice;
public $familyprice;
public $partyprice;

protected $inputFilter;

public function exchangeArray($data)
    {
        $this->id            = (!empty($data['id']))         ? $data['id']         : null;
        $this->title         = (!empty($data['title']))      ? $data['title']      : null;
        $this->zutaten       = (!empty($data['zutaten']))    ? $data['zutaten']    : null;
        $this->smallprice    = (!empty($data['smallprice'])) ? $data['smallprice'] : null;
        $this->bigprice      = (!empty($data['bigprice']))   ? $data['bigprice']   : null;
        $this->familyprice   = (!empty($data['familyprice']))? $data['familyprice']: null;
        $this->partyprice    = (!empty($data['partyprice'])) ? $data['partyprice'] : null;
    }

public function getArrayCopy()
    {
        return get_object_vars($this);
    }
public function setInputFilter(InputFilterInterface $inputFilter)
    {
        throw new \Exception("Not used");
    }
Run Code Online (Sandbox Code Playgroud)

我认为我应该支付的第三件事是module.php文件

namespace PizzaPoint;

use PizzaPoint\Model\Pizza;

use PizzaPoint\Model\PizzaTable;

use Zend\Db\ResultSet\ResultSet;

use Zend\Db\TableGateway\TableGateway;

class Module {

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(
              'PizzaPoint\Model\PizzaTable' => function($sm) 
                    {
                        $tableGateway = $sm->get('PizzaTableGateway');
                        $table = new PizzaTable($tableGateway);
                        return $table;
                    },
               'PizzaTableGateway' => function ($sm)
                    {
                       $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                       $resultSetPrototype = new ResultSet();
                       $resultSetPrototype->setArrayObjectPrototype(new Pizza());
                       return new TableGateway('pizza', $dbAdapter, null, $resultSetPrototype); 
                    },
              ),
            );
    }
Run Code Online (Sandbox Code Playgroud)

}

最后这里是根的结构:

module 
Run Code Online (Sandbox Code Playgroud)

- - -\应用

------\PizzaPoint

    2. -----\config



              3 ------\ module.config.php

    2------\src
                   3 ------\PizzaPoint
                           4 --------\Controller
                                    5 -------\PizzaController.php
                           4---------\Form
                                     5--------\PizzaForm.php
                           4 ---------\Model
                                    5--------\Pizza.php
                                    5--------\PizzaTable.php
Run Code Online (Sandbox Code Playgroud)

Tim*_*ain 5

由于你的控制器在PizzaPoint\Controller命名空间内,当你运行时new Pizza(),PHP认为你的意思new PizzaPoint\Controller\Pizza().您要么使用全局命名空间:

new \PizzaPoint\Model\Pizza()
Run Code Online (Sandbox Code Playgroud)

或者(甚至更好),添加:

use PizzaPoint\Model\Pizza;
Run Code Online (Sandbox Code Playgroud)

到控制器类的顶部(在命名空间声明下面),将该类导入当前命名空间.然后你的现有代码应该工作.