duangan9251 2014-11-08 18:57
浏览 74
已采纳

使用Composer在Zend Framework 2中自动加载Doctrine 1

I want to use Doctrine 1 inside a Zend Framework 2 project. And it has the old underscore/directory class naming style. If I am right that is compatible with the PSR0 autoloading. So I configured it as I thought would be correct. But it's not. :-(

I get the following error, when accessing my AlbumController via browser:

Fatal error: Class 'AlbumApi\Controller\Doctrine_Query' not found in /project/application_zf2/module/AlbumApi/src/AlbumApi/Controller/AlbumController.php on line [...]

Where is my misconception?

This is my project structure

/project
   /application
   /application_zf2
       /module/AlbumApi/src/AlbumApi/Controller
          /AlbumController.php
       /composer.json
       /init_autoloader.php
   /library
       /Doctrine
           /Doctrine/MoreDirectories
           /Doctrine.php

composer.json:

{
   "require": {
     "php": ">=5.3.3",
     "zendframework/zendframework": ">=2.2.4",
     "zendframework/zend-developer-tools": "dev-master"
   },

   "include-path": ["../library/Doctrine"],

   "autoload": {
      "psr-0": {
          "Doctrine_": "../library/Doctrine"
      }
   }
}

AlbumController

<?php
namespace AlbumApi\Controller;

use AlbumApi\Controller\AbstractRestfulJsonController;
use Zend\View\Model\JsonModel;

class AlbumController extends AbstractRestfulJsonController
{
    public function getList()
    {   // Action used for GET requests without resource Id
        $query = Doctrine_Query::create()
            ->from('User b')
            ->where('b.plz LIKE ?', $plz.'%');
        $result = $query->fetchArray();
        return new JsonModel($result);
    }
}
  • 写回答

1条回答 默认 最新

  • doutui8842 2014-11-08 19:19
    关注

    Doctrine 1 doesn't use namespaces, so you have to write \Doctrine_Query instead of just Doctrine_Query.

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

报告相同问题?

悬赏问题

  • ¥15 蓝桥oj3931,请问我错在哪里
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染