gpt4 book ai didi

zend-framework - 这是将 Zend Framework 与 Doctrine 2 集成的正确方法吗?

转载 作者:行者123 更新时间:2023-12-04 04:28:38 26 4
gpt4 key购买 nike

我似乎设法将 Doctrine 2 的自动加载器集成到 Zend 的,但我不确定我是否做对了......

目录结构

/application
/models
/User.php // following classes are doctrine models
/Post.php
/Tag.php
/proxies
/... // proxy classes generated by doctrine
/... // other zend classes

bootstrap.php > _initDoctrine()

// setup Zend & Doctrine Autoloaders
require_once "Doctrine/Common/ClassLoader.php";

$zendAutoloader = Zend_Loader_Autoloader::getInstance();

// $autoloader = array(new \Doctrine\Common\ClassLoader(), 'loadClass');

$autoloader = array(new \Doctrine\Common\ClassLoader('Symfony'), 'loadClass');
$zendAutoloader->pushAutoloader($autoloader, 'Symfony\\');
$autoloader = array(new \Doctrine\Common\ClassLoader('Doctrine'), 'loadClass');
$zendAutoloader->pushAutoloader($autoloader, 'Doctrine\\');
$autoloader = array(new \Doctrine\Common\ClassLoader('DoctrineExtensions'), 'loadClass');
$zendAutoloader->pushAutoloader($autoloader, 'DoctrineExtensions\\');
$autoloader = array(new \Doctrine\Common\ClassLoader('Application\\Models', realpath(__DIR__ . '/..')), 'loadClass');
$zendAutoloader->pushAutoloader($autoloader, 'Application\\Models\\');
$autoloader = array(new \Doctrine\Common\ClassLoader('Application\\Proxies', realpath(__DIR__ . '/..')), 'loadClass');
$zendAutoloader->pushAutoloader($autoloader, 'Application\\Proxies');
$autoloader = array(new \Doctrine\Common\ClassLoader('DoctrineExtensions'), 'loadClass');
$zendAutoloader->pushAutoloader($autoloader, 'DoctrineExtensions\\');

// setup configuration as seen from the sandbox application
// TODO: read configuration from application.ini
$config = new \Doctrine\ORM\Configuration;
$cache = new \Doctrine\Common\Cache\ArrayCache;
$config->setMetadataCacheImpl($cache);
$driverImpl = $config->newDefaultAnnotationDriver(realpath(__DIR__ . '/models'));
$config->setMetadataDriverImpl($driverImpl);
$config->setQueryCacheImpl($cache);
$config->setProxyDir(realpath(__DIR__ . '/proxies'));
$config->setProxyNamespace('Application\\Proxies');
$config->setAutoGenerateProxyClasses(true);

$connectionOptions = array(
'driver' => 'pdo_mysql',
'user' => 'root',
'password' => '',
'dbname' => 'learningzf'
);

// setup entity manager
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
Zend_Registry::set("em", $em);
return $em;

我有一个问题是我可以在 newDefaultAnnotationDriver()setProxyDir() 中使用相对路径吗?说我只是使用 构建完整路径是否更安全? realpath()__DIR__ 会是最安全的吗?

我还想知道 doctrine 是否要求我为每个命名空间设置自动加载 1,然后推送该自动加载器?

然后我想知道这个例子是不是here可行吗?基本上他使用了类似...

protected function _initDoctrine()
{
// 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');
spl_autoload_unregister($doctrineAutoloader);

// Fetch the global Zend Autoloader
$autoloader = Zend_Loader_Autoloader::getInstance();

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

我想知道为什么他不需要将参数从 doctrine 2 沙箱传递到 ClassLoader,命名空间被传递到自动加载器,1 到 1 并且自动加载器已注册。为什么需要 spl_autoload_unregister($doctrineAutoloader)

最佳答案

好吧,我就说是,然后关闭

关于zend-framework - 这是将 Zend Framework 与 Doctrine 2 集成的正确方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3372918/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com