使用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);
}
}
我想在Zend Framework 2项目中使用Doctrine 1。 它具有旧的下划线/目录类命名样式。 如果我是正确的,则与PSR0自动加载兼容。 所以我配置它,因为我认为是正确的。 但事实并非如此。 : - ( p>
当通过浏览器访问我的AlbumController时出现以下错误: p>
致命错误:Class'AlbumApi \ Controller \ Doctrine_Query'找不到/project/application_zf2/module/AlbumApi/src/AlbumApi/Controller/AlbumController.php在线[...]
code> pre>
我在哪里? 错误概念? p>
这是我的项目结构 p>
/ project
/ application
/ application_zf2
/ module / AlbumApi / src / AlbumApi / Controller
/AlbumController.php
/composer.json
/init_autoloader.php
/ library
/ Doctrine
/ Doctrine / MoreDirectories
/Doctrine.php
pre>
composer.json: p>
{
“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}
}
}
code> pre>
AlbumController p>
&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);
}
}
code> pre>
div>
Doctrine 1 doesn't use namespaces, so you have to write \Doctrine_Query
instead of just Doctrine_Query
.