2015-06-19 28 views
10

Quando faccio una query semplice, come trovare tutti gli utenti, restituisce una matrice vuota. $users = $em->getRepository('MyApp\\Model\\Entity\\User')->findAll();Doctrine non trova i dati su Google App Engine?

Tuttavia, quando mi collego al mio database manualmente, utilizzando PDO, trova i dati. Sto usando il metodo ArrayCache per assicurarmi che non abbia nulla a che fare con GAE che non ha un filesystem. I documenti GAE dicono che puoi usare sys_get_temp_dir(), quindi non penso che siano i miei proxy. Non riesco a capire perché Doctrine non restituisca nulla e non abbia commesso errori.

Ecco il mio file di bootstrap per la mia app:

<?php 

$baseDir = dirname(dirname(__FILE__)); 

define('TIMEZONE_OFFSET', \MyApp\Library\Date::getMyTimezoneOffset()); 

use Doctrine\Common\Annotations\AnnotationReader; 
use Doctrine\Common\Annotations\AnnotationRegistry; 

// globally used cache driver, in production use APC or memcached 
$cache = new Doctrine\Common\Cache\ArrayCache; 
// standard annotation reader 
$annotationReader = new AnnotationReader; 
AnnotationReader::addGlobalIgnoredName('dummy'); 
AnnotationRegistry::registerFile(__DIR__ . "/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php"); 
AnnotationRegistry::registerFile(__DIR__ . "/Gedmo/Timestampable/Mapping/Driver/Annotation.php"); 
AnnotationRegistry::registerAutoloadNamespace("\\MyApp\\Model\\Entity", $baseDir); 
$cachedAnnotationReader = new Doctrine\Common\Annotations\CachedReader(
    $annotationReader, // use reader 
    $cache, // and a cache driver 
    $debug = LOCAL 
); 
// create a driver chain for metadata reading 
$driverChain = new Doctrine\ORM\Mapping\Driver\DriverChain(); 
// load superclass metadata mapping only, into driver chain 
// also registers Gedmo annotations.NOTE: you can personalize it 
Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM(
    $driverChain, // our metadata driver chain, to hook into 
    $cachedAnnotationReader // our cached annotation reader 
); 

// now we want to register our application entities, 
// for that we need another metadata driver used for Entity namespace 
$annotationDriver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver(
    $cachedAnnotationReader, // our cached annotation reader 
    array(ENTITY_PATH) // paths to look in 
); 
// NOTE: driver for application Entity can be different, Yaml, Xml or whatever 
// register annotation driver for our application Entity namespace 
$driverChain->addDriver($annotationDriver, 'MyApp\\Model\\Entity'); 

// general ORM configuration 
$config = new Doctrine\ORM\Configuration; 
$config->setProxyDir(sys_get_temp_dir()); 
$config->setProxyNamespace('Proxy'); 
$config->setAutoGenerateProxyClasses(Doctrine\Common\Proxy\AbstractProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS); // this can be based on production config. 
// register metadata driver 
$config->setMetadataDriverImpl($driverChain); 
// use our already initialized cache driver 
$config->setMetadataCacheImpl($cache); 
$config->setQueryCacheImpl($cache); 

// create event manager and hook preferred extension listeners 
$evm = new Doctrine\Common\EventManager(); 
// gedmo extension listeners, remove which are not used 

// timestampable 
$timestampableListener = new Gedmo\Timestampable\TimestampableListener; 
$timestampableListener->setAnnotationReader($cachedAnnotationReader); 
$evm->addEventSubscriber($timestampableListener); 

// mysql set names UTF-8 if required 
$evm->addEventSubscriber(new Doctrine\DBAL\Event\Listeners\MysqlSessionInit()); 

$dbParams = array(
    'driver' => 'pdo_mysql', 
    'user' => DB_USER, 
    'password' => DB_PASSWORD, 
    'dbname' => DB_NAME, 
    'host' => DB_HOST, 
    'port' => DB_PORT, 
    'unix_socket' => DB_UNIX_SOCKET 
); 

// Finally, create entity manager 
$em = Doctrine\ORM\EntityManager::create($dbParams, $config, $evm); 

Aggiornamento

Solo per chiarezza:

Ciò restituisce un array vuoto:

$users = $em->getRepository('MyApp\\Model\\Entity\\User')->findAll(); 
\Doctrine\Common\Util\Debug::dump($users); 

E questo restituisce un array con utenti al suo interno. Così confuso.

$pdo = $em->getConnection(); 
$users = $pdo->query('SELECT * FROM user'); 
var_dump($users->fetchAll()); 
+0

* "Non gettare eventuali errori" * - Aggiungi la segnalazione degli errori per la parte superiore del file (s) subito dopo l'apertura tag PHP ad esempio '

+0

@ Fred-ii- Ho fatto come hai detto, ancora nessun errore. =/ – GreeKatrina

+0

probabilmente dovresti postare cosa fa la funzione 'findAll()'. Questa non è una funzione principale di PDO. consultare il manuale http://php.net/manual/en/pdostatement.fetch.php –

risposta