[英]ZF2 ODM MongoDB “need to login”
i'm using ZF2 with ODM and MongoDB. 我将ZF2与ODM和MongoDB结合使用。 When i try to perform very simple tasks like:
当我尝试执行非常简单的任务时,例如:
/** @ODM\Document(collection="Test") */
class Test
{
...
}
I receive the Error "need to login". 我收到错误消息“需要登录”。 Well, i know why this is a problem an i can solve it by using:
好吧,我知道为什么这是一个问题,我可以使用以下方法解决:
/** @ODM\Document(db="mongoDB", collection="Test") */
class Test
{
...
}
Instead of using the db declaration the whole time in every class, is there a way to add config values from the .local/.global config file or can i just reconfigure the configure options? 有没有一种方法可以从.local / .global配置文件中添加配置值,而不是在每个类中始终使用db声明,还是可以重新配置配置选项?
Thank you very much. 非常感谢你。
Have a read through this useful tutorial about implementing Doctrine with ZF2. 通读这篇有关使用ZF2实现Doctrine的有用教程 。 You should be placing global configuration options in Module.php and config/local.php.
您应该在Module.php和config / local.php中放置全局配置选项。 This array key in Module.php:
Module.php中的此数组键:
'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
)
)
)
)
And these DB connection parameters in local.php: 这些在local.php中的数据库连接参数:
return array(
// ...
'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'host' => 'localhost',
'port' => '3306',
'user' => '',
'password' => '',
'dbname' => 'zf2tutorial',
)
)
)
),
);
This will allow you to avoid repetition in your DB entities, allowing you to use just the following Doctrine declarations for each of your classes: 这将使您避免在数据库实体中重复,从而允许您对每个类仅使用以下Doctrine声明:
/**
* A music album.
*
* @ORM\Entity
* @ORM\Table(name="album")
* @property string $artist
* @property string $title
* @property int $id
*/
class Album implements InputFilterAwareInterface {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.