2013-02-10 94 views
0
<?php 

    use vendor\doctrine\common\lib\Doctrine\Common\ClassLoader, 
    vendor\doctrine\orm\lib\Doctrine\ORM\EntityManager; 

    require 'vendor/doctrine/common/lib/Doctrine/Common/ClassLoader.php' or die(); 

    $loader = new ClassLoader("Doctrine"); 
    $loader->register(); 

    $dbParams = array(
     'driver' => 'pdo_mysql', 
     'user' => 'root', 
     'password' => 'password', 
     'dbname' => 'test_doctrine' 
    ); 
    $path = 'entities/'; 
    $config = Setup::createAnnotationMetadataConfiguration($path, true); 
    $entityManager = EntityManager::create($dbParams, $config); 

    $user=new User(); 
    $post=new Post($user); 

    $post->addComment("First comment"); 
    $post->addComment("Seconde comment"); 

    $entityManager->persist($user); 
    $entityManager->persist($post); 
    $entityManager->flush(); 

?> 

我得到這個錯誤:主義ClassLoader.php「未能打開流:沒有這樣的文件或目錄」

Warning: require(1): failed to open stream: No such file or directory in /var/www/tests/index.php on line 8

Fatal error: require(): Failed opening required '1' (include_path='.:/usr/share/php:/usr/local/lib/smarty-3.1.13/libs') in /var/www/tests/index.php on line 8

有人可以幫助我瞭解什麼是錯在這裏嗎?

+0

經常遇到此錯誤,並快速排除故障,請按照下列步驟操作:https://stackoverflow.com/a/36577021/2873507 – 2016-04-12 15:33:31

回答

0

一些奇怪的是 ...必需的 '1' ...

反正檢查1)和需要2)或進一步的信息。

1)在第8行之前,get_included_files顯示了包含文件的列表。檢查ClassLoader.php是否已加載。 2)新的ClassLoader(「Doctrine」)將在您的PHP include_path中找到Doctrine *名稱空間。這包括。(當前路徑)在你的情況下,在這裏檢查你的Doctrine庫(子目錄也可以)。

相關問題