我必须使用symfony实体SrvrsServers
和NcBackupEvents
:
关系代码:
/**
* One SrvrsServers has Many NcBackupEvents.
* @ORM\OneToMany(targetEntity="NcBackupEvents", mappedBy="SrvrsServers")
*/
private $ncBackupEvents;
public function __construct() {
$this->ncBackupEvents = new ArrayCollection();
}
这是NcBackupEvents
:
/**
* @var \SrvrsServers
*
* @ORM\ManyToOne(targetEntity="SrvrsServers")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="srvrs_servers_id", referencedColumnName="id")
* })
*/
private $srvrsServers;
从SrvrsServers
到NcBackupEvents
的关系是一对多。在NcBackupEvents
的回购中我能够获取有关自身的信息。这有效,我认为SrvrsServers
对象被拉了,但我不是100%肯定,也不知道如何访问它:
class NcBackupEventsRepository extends \Doctrine\ORM\EntityRepository
{
public function findByServerBackup($parameters)
{
$dql = 'SELECT n FROM NCbrtBundle:NcBackupEvents n
WHERE n.backupmethod LIKE :backupmethod
AND n.backupType LIKE :backup_type
AND n.log LIKE :log';
$query = $this->getEntityManager()
->createQuery($dql)
->setParameter('backupmethod',
'%'.$parameters['backupmethod'].'%')
->setParameter('backup_type',
'%'.$parameters['backup_type'].'%')
->setParameter('log', '%'.$parameters['log'].'%');
try {
return $query->getResult();
} catch (\Doctrine\ORM\NoResultException $e) {
return null;
}
}
}
如何使用SrvrsServers->name
字段来实现Controller的QUERY?我尝试过很多东西,似乎没什么用。这应该很简单,但我不明白如何完成它。我试图遵循official docs并且由于某种原因无法使其工作。有人能指出我这样做的方法吗?请保持在场,我是新手。
编辑:SAMPLE Controller。
/**
* @Route("/")
*/
public function indexAction()
{
$paramaters = array('backupmethod' => 't-py',
'backup_type' => '', 'log' => 'fuc');
$em = $this->getDoctrine()
->getRepository('NCbrtBundle:NcBackupEvents')
->findByServerBackup($paramaters);
foreach($em as $value){
print_r(gettype($value));
print_r($value->getSrvrsServers()->getName());
}
return $this->render('NCbrtBundle:Default:index.html.twig');
}
EDIT2:我想将服务器name
包含在$paramaters
实体的SrvrsServers
变量中