0

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);
    }
}
NoradX
  • 53
  • 1
  • 1
  • 6
  • Last commit to Doctrine 1 made by Benjamin Eberlei on April 2012. Why you need to use that ancient library? – edigu Nov 08 '14 at 19:11
  • I knew someone would come up with a question like this. ;-) – NoradX Nov 09 '14 at 12:19
  • 1.) Doctrine 1 supports foreign key as primary key and nested sets, which Doctrine 2 doesn't. 2.) I do the project I am working on in my spare time. Migrating all the model code and services to Doctrine 2 would require at least 1 week full time, which means 1 months spare time working. And I do invest a lot of time already to migrate from ZF1 to ZF2. The support for the main branches is way to short in my eyes. Which is a problem common to PHP libraries, I think. – NoradX Nov 09 '14 at 12:40

1 Answers1

1

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

AlexP
  • 9,906
  • 1
  • 24
  • 43
akond
  • 15,865
  • 4
  • 35
  • 55
  • Oh, thank you so much. It works now. Then I don't understand namespaces well enough. So I must prepend the backslash as soon I use a namespace for my file? – NoradX Nov 09 '14 at 11:04