0

Zend Framework1.11とDoctrine2を統合するために、次の記事の手順に従いました。

http://jeboy25.blogspot.com/2010/08/doctrine-2-and-zend-framework-110.html

そして私は記事について3つの質問があります:

1-「SchemaToolClass」セクションで、作成者がZendProject / public / index.phpファイルの下部の次の後にschema_tool.phpを含める理由がわかりません:$ application-> bootstrap()-> run();

2-コマンド「phpdoctrineorm:schema-tool:create」を実行すると、コマンドラインに次のエラーメッセージが表示されます。HPスタックトレース:PHP 1. {main}()/ Library / WebServer / Documents / carlending / application / tools / doctrine:0 PHP 2. include()/ Library / WebServer / Documents / carlending / application / tools / doctrine:7 PHP 3. require()/ Library / WebServer / Documents / carlending / application / tools/doctrine。 php:41 PHP 4. Doctrine \ Common \ ClassLoader-> loadClass($ className = uninitialized)エラーはcli-config.phpファイルの'$ config = new \ Doctrine \ ORM \ Configuration();'の行で発生します。

3-作成者がDoctrineで生成されたプロキシとモデルをドメインフォルダ内に配置する理由を説明できますか。他のモデルクラスと同じように、modelsフォルダーにある方が良いのではないでしょうか。モデル内で「生成された」フォルダーを使用しているプログラマーもいます。

Zend 1.xとDoctrineをうまく統合できたなら、非常に役立つ実用的なプロジェクトを送っていただければ幸いです。

ご協力いただきありがとうございます。

4

2 に答える 2

1

http://www.doctrine-project.org/docs/orm/2.1/en/tutorials/getting-started-xml-edition.htmlの「EntityManager の取得」セクションを読んだ後

ブートストラップするには、次の 3 行が必要だと思います。

use Doctrine\ORM\Tools\Setup;
require_once 'Doctrine/ORM/Tools/Setup.php';
Setup::registerAutoloadPEAR();
于 2011-10-31T22:31:32.000 に答える
0

数週間前に動作するようになりました。これが私のコードです。Doctrine 2は本当にいいです:)

私のブートストラップで

/**
 * Initialize auto loader of Doctrine
 *
 * @return Doctrine_Manager
 */
protected function _initDoctrine() {
    $this->bootstrap('autoload');

    require_once('Doctrine/Common/ClassLoader.php');

    // Create the doctrine autoloader and remove it from the spl autoload stack (it adds itself)
    require_once 'Doctrine/Common/ClassLoader.php';
    $doctrineAutoloader = array(new \Doctrine\Common\ClassLoader(), 'loadClass');
    //$doctrineAutoloader->register();
    spl_autoload_unregister($doctrineAutoloader);

    $autoloader = Zend_Loader_Autoloader::getInstance();

    // Push the doctrine autoloader to load for the Doctrine\ namespace
    $autoloader->pushAutoloader($doctrineAutoloader, 'Doctrine');

    $classLoader = new \Doctrine\Common\ClassLoader('Entities', realpath(__DIR__ . '/models/'), 'loadClass');
    $autoloader->pushAutoloader(array($classLoader, 'loadClass'), 'Entities');

    $classLoader = new \Doctrine\Common\ClassLoader('Symfony', realpath(__DIR__ . '/../library/Doctrine/'), 'loadClass');
    $autoloader->pushAutoloader(array($classLoader, 'loadClass'), 'Symfony');

    $doctrineConfig = $this->getOption('doctrine');
    $config = new \Doctrine\ORM\Configuration();

    $cache = new \Doctrine\Common\Cache\ArrayCache;
    $config->setMetadataCacheImpl($cache);
    $config->setQueryCacheImpl($cache);

    $driverImpl = new Doctrine\ORM\Mapping\Driver\YamlDriver(APPLICATION_PATH . '/../configs/mappings/yaml');
    //$driverImpl = $config->newDefaultAnnotationDriver($doctrineConfig['path']['entities']);
    $config->setMetadataDriverImpl($driverImpl);

    $config->setProxyDir(APPLICATION_PATH . '/../proxies');
    $config->setProxyNamespace('App\Proxies');

    $connectionOptions = array(
        'driver' => $doctrineConfig['conn']['driv'],
        'user' => $doctrineConfig['conn']['user'],
        'password' => $doctrineConfig['conn']['pass'],
        'dbname' => $doctrineConfig['conn']['dbname'],
        'host' => $doctrineConfig['conn']['host']
    );

    $registry = Zend_Registry::getInstance();
    $registry->entitymanager = $em;

    return $em;
}

スキーマなど

上記のようにyamlを使用しています。チュートリアルは読んでいませんが、魅力的に機能するコマンドラインツール、私のdoctrine.php(APPLICATION/binにあります)を使用しました:

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/..'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path()
)));

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/../configs/application.ini'
);

$application->getBootstrap()->bootstrap('doctrine');


require_once __DIR__ . '/../Bootstrap.php';

$em = $application->getBootstrap()->getResource('doctrine');

$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
    'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em, APPLICATION_PATH . "/configs/mappings")
));

\Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet);

最初にエンティティを生成する必要があります。

  • 削除せずにすべてのモデルを生成し、注釈も作成します - ./doctrine orm:generate-entities ~/Public/my_app/application/models/ --regenerate-entities 0 --generate-annotations 1

次に、スキーマを生成します ./doctrine orm:schema-tool:create --dump-sql または ./doctrine orm:schema-tool:update --dump-sql

プロキシは実際にはモデルの一部ではなく、Doctrine が内部的に使用しているだけなので、models フォルダーとは別のエンティティとして配置しましたが、実際には問題ではないと思います: ./doctrine orm:generate-proxies ~ /パブリック/my_app/プロキシ/

apache グループのプロキシに書き込み権限を追加することを忘れないでください。

うーん...私はJeboyのソリューションを十分に説明していないと思いますが、おそらく私のコードはあなたが始めるのに役立ちます.しばらく時間がかかりました. " 各モデルで(自動的に生成される必要があります)

于 2011-01-05T22:01:32.583 に答える