2015-06-19 11 views
10

जब मैं एक साधारण क्वेरी करता हूं, जैसे सभी उपयोगकर्ताओं को ढूंढना, यह एक खाली सरणी देता है। $users = $em->getRepository('MyApp\\Model\\Entity\\User')->findAll();सिद्धांत Google App Engine पर डेटा नहीं ढूंढ रहा है?

हालांकि, जब मैं पीडीओ का उपयोग करके मैन्युअल रूप से अपने डेटाबेस से कनेक्ट करता हूं, तो यह डेटा पाता है। मैं यह सुनिश्चित करने के लिए ऐरे कैश विधि का उपयोग कर रहा हूं, जीएई के पास फाइल सिस्टम नहीं होने के साथ इसका कोई लेना-देना नहीं है। जीएई दस्तावेज़ कहते हैं कि आप sys_get_temp_dir() का उपयोग कर सकते हैं, इसलिए मुझे नहीं लगता कि यह मेरी प्रॉक्सी है। मुझे नुकसान हुआ है कि क्यों डॉक्टर कुछ भी वापस नहीं कर रहा है और किसी भी त्रुटि को फेंक नहीं रहा है।

<?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); 

अद्यतन

बस स्पष्टता के लिए

:

यह एक खाली सरणी देता है:

यहाँ मेरी अनुप्रयोग के लिए मेरी बूटस्ट्रैप फ़ाइल है

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

और यह एक रिटर्न इसमें उपयोगकर्ताओं के साथ सरणी। इतनी उलझन।

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

* * "किसी भी त्रुटि फेंक नहीं" - 'उदाहरण के लिए <अपने उद्घाटन पीएचपी टैग के बाद सही अपनी फ़ाइल (रों) के शीर्ष के लिए रिपोर्टिंग त्रुटि जोड़ें? PHP त्रुटि_ रिपोर्टिंग (E_ALL); ini_set ('display_errors', 1); फिर आपका शेष कोड, यह देखने के लिए कि क्या यह कुछ भी उत्पन्न करता है। यदि आप पहले से ऐसा नहीं कर रहे हैं तो अपने पीडीओ पर भी त्रुटियों की जांच करें http://php.net/manual/en/pdo.error-handling.php। –

+0

@ फ्रेड-आईआई- मैंने जैसा कहा आपने किया, अभी भी कोई त्रुटि नहीं है। =/ – GreeKatrina

+0

आपको शायद 'findAll()' फ़ंक्शन क्या पोस्ट करना चाहिए। यह पीडीओ कोर फ़ंक्शन नहीं है। मैनुअल http://php.net/manual/en/pdostatement.fetch.php –

उत्तर

3

मेरे मुद्दा, था कि मैं अपने डेटाबेस में एक कंपनी का निर्माण नहीं किया और मेरे उपयोगकर्ता इकाई एक कंपनी की आवश्यकता है ताकि सिद्धांत एक अंदरूनी शामिल हों और इस प्रकार, किसी भी उपयोगकर्ता ने इस्तेमाल किया। ओह।

अद्यतन

इस सवाल देखें: Why does Doctrine2 do an INNER JOIN for findAll()?