首页 文章

zend framework2教程:致命错误:在C:\ wamp \ www \ quickstart \ module \ Album \ Module.php中找不到类'Album\Model\AlbumTable'

提问于
浏览
0

注意:开发在Netabean IDE中完成,托管在WAMPP上是本地的,我已经为虚拟主机配置了它 . 正在使用Composer .

我已经回顾了与此类似的其他问题,我没有同样的问题 . 请注意这是我第一次使用Zend框架 . 谢谢 .

回声的使用帮助我找到了当我在Module.php中创建AlbumTable时它失败了 .

这是Stacktrace:

[2015年3月30日20:29:11欧洲/巴黎] PHP致命错误:第43行的C:\ wamp \ www \ quickstart \ module \ Album \ Module.php中找不到“专辑\模型\专辑表”类[2015年3月30日20:29:11欧洲/巴黎] PHP Stack追踪:[2015年3月30日20:29:11欧洲/巴黎] PHP 1. ()C:\ wamp \ www \ quickstart \ public \ index.php:0 [2015年3月30日20:29:11欧洲/巴黎] PHP 2. Zend \ Mvc \ Application-> run()C:\ wamp \ www \ quickstart \ public \ index.php :26 [30-Mar-2015 20:29:11 Europe / Paris] PHP 3. Zend \ EventManager \ EventManager-> trigger()C:\ wamp \ www \ quickstart \ vendor \ zendframework \ zendframework \ library \ Zend \ Mvc \ Application.php:313 [2015年3月30日20:29:11欧洲/巴黎] PHP 4. Zend \ EventManager \ EventManager-> triggerListeners()C:\ wamp \ www \ quickstart \ vendor \ zendframework \ zendframework \ library \ Zend \ EventManager \ EventManager.php:207 [2015年3月30日20:29:11欧洲/巴黎] PHP 5. call_user_func:{C:\ wamp \ www \ quickstart \ vendor \ zendframework \ zendframework \ library \ Zend \ EventManager \ EventManager.php:468}()C:\ wamp \ www \ quickstart \ vendor \ zendfr amework \ zendframework \ library \ Zend \ EventManager \ EventManager.php:468 [2015年3月30日20:29:12欧洲/巴黎] PHP 6. Zend \ Mvc \ DispatchListener-> onDispatch()C:\ wamp \ www \ quickstart \ vendor \ zendframework \ zendframework \ library \ Zend \ EventManager \ EventManager.php:468 [2015年3月30日20:29:12欧洲/巴黎] PHP 7. Zend \ Mvc \ Controller \ AbstractController-> dispatch()C :\ wamp \ www \ quickstart \ vendor \ zendframework \ zendframework \ library \ Zend \ Mvc \ DispatchListener.php:113 [30-Mar-2015 20:29:12 Europe / Paris] PHP 8. Zend \ EventManager \ EventManager-> trigger()C:\ wamp \ www \ quickstart \ vendor \ zendframework \ zendframework \ library \ Zend \ Mvc \ Controller \ AbstractController.php:116 [30-Mar-2015 20:29:12 Europe / Paris] PHP 9. Zend \ EventManager \ EventManager-> triggerListeners()C:\ wamp \ www \ quickstart \ vendor \ zendframework \ zendframework \ library \ Zend \ EventManager \ EventManager.php:207 [2015年3月30日20:29:12欧洲/巴黎] PHP 10. call_user_func:{C:\ wamp \ www \ quickstart \ vendor \ zendframework \ zendframework \ library \ Zend \ EventManager \ EventMan ager.php:468}()C:\ wamp \ www \ quickstart \ vendor \ zendframework \ zendframework \ library \ Zend \ EventManager \ EventManager.php:468 [30-Mar-2015 20:29:12 Europe / Paris] PHP 11. Zend \ Mvc \ Controller \ AbstractActionController-> onDispatch()C:\ wamp \ www \ quickstart \ vendor \ zendframework \ zendframework \ library \ Zend \ EventManager \ EventManager.php:468 [30-Mar-2015 20:29: 12欧洲/巴黎] PHP 12.专辑\控制器\ AlbumController-> indexAction()C:\ wamp \ www \ quickstart \ vendor \ zendframework \ zendframework \ library \ Zend \ Mvc \ Controller \ AbstractActionController.php:83 [30-Mar -2015 20:29:12欧洲/巴黎] PHP 13.专辑\ Controller \ AlbumController-> getAlbumTable()C:\ wamp \ www \ quickstart \ module \ Album \ src \ Album \ Controller \ AlbumController.php:26 [30 -Mar-2015 20:29:12欧洲/巴黎] PHP 14. Zend \ ServiceManager \ ServiceManager-> get()C:\ wamp \ www \ quickstart \ module \ Album \ src \ Album \ Controller \ AlbumController.php:51 [2015年3月30日20:29:12欧洲/巴黎] PHP 15. Zend \ ServiceManager \ ServiceManager-> create()C:\ wamp \ www \ quickstart \ vendor \ ze ndframework \ zendframework \ library \ Zend \ ServiceManager \ ServiceManager.php:525 [2015年3月30日20:29:12欧洲/巴黎] PHP 16. Zend \ ServiceManager \ ServiceManager-> doCreate()C:\ wamp \ www \ quickstart \ vendor \ zendframework \ zendframework \ library \ Zend \ ServiceManager \ ServiceManager.php:593 [2015年3月30日20:29:12欧洲/巴黎] PHP 17. Zend \ ServiceManager \ ServiceManager-> createFromFactory()C:\ wamp \ www \ quickstart \ vendor \ zendframework \ zendframework \ library \ Zend \ ServiceManager \ ServiceManager.php:633 [2015年3月30日20:29:12欧洲/巴黎] PHP 18. Zend \ ServiceManager \ ServiceManager-> createServiceViaCallback( )C:\ wamp \ www \ quickstart \ vendor \ zendframework \ zendframework \ library \ Zend \ ServiceManager \ ServiceManager.php:1057 [2015年3月30日20:29:12欧洲/巴黎] PHP 19. call_user_func:{C: \瓦帕\ WWW \快速启动\厂商\ zendframework \ zendframework \库\ Zend的\的ServiceManager \ ServiceManager.php:923}()C:\ wamp \ www \ quickstart \ vendor \ zendframework \ zendframework \ library \ Zend \ ServiceManager \ ServiceManager.php:923 [2015年3月30日20:29:12欧洲/巴黎] PHP 20.专辑\模块 - >专辑()C:\ wamp \ www \ quickstart \ vendor \ zendframework \ zendframework \ library \ Zend \ ServiceManager \ ServiceManager.php:923

这是我的Album \ src \ Album \ Controller \ AlbumController.php

namespace Album\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class AlbumController extends AbstractActionController
{
protected $albumTable;

public function indexAction()
{
     return new ViewModel(array(
         'albums' => $this->getAlbumTable()->fetchAll(),
     ));
}

public function getAlbumTable()
{
    echo "Made it";
    if (!$this->albumTable) {
        $sm = $this->getServiceLocator();
        echo "Made it";
        if($sm->has('Album\Model\AlbumTable'))
        {
            echo "FOUND Album\Model\AlbumTable";
            $this->albumTable = $sm->get('Album\Model\AlbumTable');
        }else{
           echo "Could not find Album\Model\AlbumTable";
        }
    }
    echo "Made it";
    return $this->albumTable;
}
}

这是Album \ Module.php

namespace Album;

use Album\Model\Album;
use Album\Model\AlbumTable;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;

use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;

class Module implements AutoloaderProviderInterface, ConfigProviderInterface
{
    public function getAutoloaderConfig()
    {
    }

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

    public function getServiceConfig()
    {
        return array(
            'factories' => array(
                'Album\Model\AlbumTable' =>  function($sm) {
                   // echo "inside ftn Album\Model\AlbumTable";
                    $tableGateway = $sm->get('AlbumTableGateway');
                    echo " Gate way GOOD";
                    $table = new AlbumTable($tableGateway);
                    echo "Table good";
                    return $table;
                },
                'AlbumTableGateway' => function ($sm) {
                   // echo "inside ftn AlbumTableGateway";
                    $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                  //  echo "adapater good";
                    $resultSetPrototype = new ResultSet();
                    $resultSetPrototype->setArrayObjectPrototype(new Album());
                    return new TableGateway('album', $dbAdapter, null, $resultSetPrototype);
                },
            ),
        );
     }

}

这是Album \ src \ Album \ Model \ AlbumTable.php

namespace Album\Model;

use Zend\Db\TableGateway\TableGateway;
//use Zend\Db\ResultSet\ResultSet;

class AlbumTable
{
    protected $tableGateway;

    public function __construct(TableGateway $tableGateway)
    {
        echo "inside construct of AlbumTable";
        $this->tableGateway = $tableGateway;
    }

我没有进入AlbumTable . 我已经将它包含在Module.php中,并使用了类名和文件拼写正确 . 除非我的眼睛让我失望,我希望情况如此 .

谁能告诉我为什么我会收到这个错误?我从回声中输出的内容如下:

Made it Made it FOUND Album\Model\AlbumTable Gate way GOOD

3 回答

  • 0

    在使用深入教程搜索我自己问题的答案时,我会在 Album\Module.php 中看到您编写以下内容:

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

    当我使用这些斜杠,并重新加载索引页面时,我得到一个空白页面 . 如果我 change the slashes 匹配教程中指示的内容,如下所示:

    return include __DIR__ . '/config/module.config.php';
    

    然后索引页面按预期加载 . 您可能有其他错误,但我可以测试并确认 .

  • 0

    无法找到 class . 如果您没有使用composer(或其他一些自动加载方法),则需要在 getAutoloaderConfig 中返回正确的配置,以将模块的命名空间添加到默认的 Zend\Loader\StandardAutoloader .

    public function getAutoloaderConfig()
    {
        return [
            'Zend\Loader\StandardAutoloader' => [
                'namespaces' => [
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                ],
            ],
        ];
    }
    
  • 1

    我有同样的问题 . 在我的情况下,这是因为我没有在Module / Album / Module.php中粘贴以下行:

    use Album\Model\Album;
    

    因为教程中没有以黄色突出显示 .

    你需要那条线!

相关问题