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

このエラーが発生します:

警告:require(1):ストリームを開くことができませんでした:8行目の/var/www/tests/index.phpにそのようなファイルまたはディレクトリはありません

致命的なエラー:require():/ var / www / tests /でrequired'1'(include_path ='。:/ usr / share / php:/ usr / local / lib / smarty-3.1.13 / libs')を開くことができませんでした8行目のindex.php

誰かが私がここで何が悪いのかを理解するのを手伝ってもらえますか?

4

1 に答える 1

0

... '1' が必要...

とにかく、1) と 2) を確認するか、必要な追加情報を確認してください。

1) 8 行目より前のget_included_filesは、含まれるファイルのリストを表示します。ClassLoader.php が読み込まれたことを確認します。

2) new ClassLoader("Doctrine") は、PHP の include_path で Doctrine* 名前空間を見つけます。これには .(現在のパス) が含まれます。これで Doctrine ライブラリを確認してください (サブディレクトリも問題ありません)。

于 2013-02-24T00:26:09.570 に答える