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

使用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);
    }
}

图片转代码服务由CSDN问答提供 功能建议

我想在Zend Framework 2项目中使用Doctrine 1。 它具有旧的下划线/目录类命名样式。 如果我是正确的,则与PSR0自动加载兼容。 所以我配置它,因为我认为是正确的。 但事实并非如此。 : - (

当通过浏览器访问我的AlbumController时出现以下错误:

 致命错误:Class'AlbumApi \ Controller \  Doctrine_Query'找不到/project/application_zf2/module/AlbumApi/src/AlbumApi/Controller/AlbumController.php在线[...] 
   
 
 

我在哪里? 错误概念?

这是我的项目结构

  / 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”:“&gt; = 5.3.3”,  
“zendframework / zendframework”:“&gt; = 2.2.4”,
“zendframework / zend-developer-tools”:“dev-master”
},
 
“include-path”:[“  ../library/Doctrine"],
n“autoload”:{
“psr-0”:{
“Doctrine_”:“../ library / Doctrine”\  n} 
} 
} 
   
 
 

AlbumController

 &lt;?php 
namespace AlbumApi \ Controller;  
 
use AlbumApi \ Controller \ AbstractRestfulJsonController; 
use Zend \ View \ Model \ JsonModel; 
 
class AlbumController扩展AbstractRestfulJsonController 
 {
公共函数getList()
 {//用于没有资源ID的GET请求的操作 
 $ query = Doctrine_Query :: create()
  - &gt; from('User b')
  - &gt; where('b.plz LIKE?',$ plz。'%'); 
 $ result  = $ query-&gt; fetchArray(); 
返回新的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.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题