doushui3216 2017-03-08 09:33
浏览 39
已采纳

Zf2扩展了类,没有找到错误类

I am trying to create the library inside the vendor folder in ZF2. Here is the structure:

/Vendor
     /Mylib
          /Mylib.php
          /MylibStore.php
          /MylibError.php
          ....

I have declared the same lib in Applicaiotion/Module.php:

public function getAutoloaderConfig()
{
    return array(
        'Zend\Loader\StandardAutoloader' => array(
            'namespaces' => array(
                 'Mylib' => __DIR__ . '/../../vendor/Mylib',
            ),
        ),
    );
}

Now I am calling Mylib class in controller it is working but when I am trying to instantiate other class in controller it is giving the error. Here is snap of code:

Mylib.php

namespace Mylib;
abstract class Mylib
{ 

MylibStore.php

namespace MylibStore;
use \Mylib\MylibError;
class MylibStore extends MylibError
{

MylibError.php

namespace MylibError;
class MylibError
{

I am getting the following error :

Fatal error: Class 'MylibStore\MylibError' not found in C:\xampp\htdocs\coxaxle\vendor\Mylib\MylibStore.php on line 5

Please let me know what I am doing wrong? And how can I resolve this issue?

  • 写回答

1条回答 默认 最新

  • dosc9472 2017-03-08 11:18
    关注

    Problem is in your namespaces. All your files inside Mylib directory should have same namespace- Mylib.
    That's why only Mylib class works, because it has correct namespace.

    If you put your classes in separate directories then you have to update namespace about this directory.

    Example:

    /Vendor
         /Mylib
              /Service
                  /MylibService.php
              /Mylib.php
              ....
    

    Class Mylib should have namespace Mylib
    Class MylibService should have namespace Mylib\Service

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

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助