我使用的是Doctrine2和Laravel 5.1。
在我的database.php中,我设置了一个名为' adm'的新连接。
' mysql'连接是默认设置。
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
'adm' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => 'admin_condo',
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
]
在我的模型中,我使用像这样的实体管理器:
class TemplateDAO
{
protected $em;
const ENTITY = 'App\Model\Entities\Template';
public function __construct (EntityManagerInterface $em, Validate $validate)
{
$this->em = $em;
$this->validate = $validate;
}
public function create($data)
{
$obj = Factory::create($data);
$this->em->persist($obj);
$this->em->flush($obj);
}
public function retrieve($id)
{
$obj = $this->em->getRepository(self::ENTITY)->find(['id' => $id]);
return Factory::retrieve($obj);
}
...
我想知道,我需要改变什么 DAO文件,坚持在' adm'不在默认数据库中?