本文整理汇总了PHP中Doctrine\ORM\EntityManager::find方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManager::find方法的具体用法?PHP EntityManager::find怎么用?PHP EntityManager::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\EntityManager
的用法示例。
在下文中一共展示了EntityManager::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: verifyBrands
private function verifyBrands()
{
for ($i = 1; $i <= 10; ++$i) {
/* @var $brand \Hautelook\AliceBundle\Tests\SymfonyApp\TestBundle\Entity\Brand */
$this->entityManager->find('Hautelook\\AliceBundle\\Tests\\SymfonyApp\\TestBundle\\Entity\\Brand', $i);
}
}
示例2: storeLocation
/**
* @param $location_id
* @param array $resources
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function storeLocation($location_id, array $resources)
{
$location = $this->em->find('riki34GameBundle:Location', $location_id);
$this->jsonLoader->storeFile($location->getFile(), $resources);
$message = "Location saved";
return $this->response->generateSuccessResponse(array($message));
}
示例3: getMainAdvs
public function getMainAdvs()
{
$advs = ['trade' => [], 'find' => [], 'gift' => []];
$qb = $this->em->createQueryBuilder();
$trade = $qb->select('a')->from('NaidusvoeBundle:Advertisment', 'a')->where($qb->expr()->andX($qb->expr()->isNotNull('a.onMainUntill'), $qb->expr()->eq('a.typeID', Advertisment::TRADE)))->getQuery()->getResult();
$type = $this->em->find('NaidusvoeBundle:AdvertismentType', Advertisment::TRADE);
$advsCount = count($trade);
$advs['trade'] = $this->getRandom($trade, AdvertisementService::MAIN_ADV_COUNT);
if ($advsCount < 5) {
$advs['trade'] = array_merge($advs['trade'], $this->generateDummyAdvs(AdvertisementService::MAIN_ADV_COUNT - $advsCount, $type));
}
$qb = $this->em->createQueryBuilder();
$find = $qb->select('a')->from('NaidusvoeBundle:Advertisment', 'a')->where($qb->expr()->andX($qb->expr()->isNotNull('a.onMainUntill'), $qb->expr()->eq('a.typeID', Advertisment::FIND)))->getQuery()->getResult();
$type = $this->em->find('NaidusvoeBundle:AdvertismentType', Advertisment::FIND);
$advsCount = count($find);
$advs['find'] = $this->getRandom($find, AdvertisementService::MAIN_ADV_COUNT);
if ($advsCount < 5) {
$advs['find'] = array_merge($advs['find'], $this->generateDummyAdvs(AdvertisementService::MAIN_ADV_COUNT - $advsCount, $type));
}
$qb = $this->em->createQueryBuilder();
$gift = $qb->select('a')->from('NaidusvoeBundle:Advertisment', 'a')->where($qb->expr()->andX($qb->expr()->isNotNull('a.onMainUntill'), $qb->expr()->eq('a.typeID', Advertisment::GIFT)))->getQuery()->getResult();
$type = $this->em->find('NaidusvoeBundle:AdvertismentType', Advertisment::GIFT);
$advsCount = count($gift);
$advs['gift'] = $this->getRandom($gift, AdvertisementService::MAIN_ADV_COUNT);
if ($advsCount < 5) {
$advs['gift'] = array_merge($advs['gift'], $this->generateDummyAdvs(AdvertisementService::MAIN_ADV_COUNT - $advsCount, $type));
}
return $advs;
}
示例4: postVoteAction
public function postVoteAction(Request $request)
{
$data = $request->getContent();
$voteData = json_decode($data, true);
$vote = new Vote();
if (isset($voteData['user_id']) && ($userId = $voteData['user_id'])) {
$user = $this->em->find('\\HackdayProject\\Entity\\User', $userId);
if (!$user) {
throw new NotFound('User cannot be found');
}
$vote->setUser($user);
}
if (isset($voteData['entry_id']) && ($entryId = $voteData['entry_id'])) {
$entry = $this->em->find('\\HackdayProject\\Entity\\Entry', $entryId);
if (!$entry) {
throw new NotFound('User cannot be found');
}
$vote->setEntry($entry);
} else {
throw new BadRequestHttpException();
}
$vote->setValue($voteData['value']);
$this->em->persist($vote);
$this->em->flush($vote);
return new JsonResponse($vote->toArray(), 201);
}
示例5: insertUpdateProcessing
public function insertUpdateProcessing(EntityManager $em, $data, $id = null)
{
$update = !is_null($id);
try {
$em->beginTransaction();
if ($update) {
$language = $em->find('Model\\Language', $id);
} else {
$language = new Language();
}
$language->setCode($data['code']);
$language->setDescription($data['description']);
$language->setFlagImageURL($data['flagimageurl']);
$menu = $em->find('Model\\Menu', $data['menuid']);
$language->setMenu($menu);
if ($update) {
$em->merge($language);
} else {
$em->persist($language);
}
$em->flush();
$em->commit();
} catch (\Exception $e) {
$em->rollback();
throw $e;
}
return $language->getId();
}
示例6: testInsertStoresCorrectValue
public function testInsertStoresCorrectValue()
{
$id = $this->driver->insert('Stuff', array('name' => 'stupid'));
$entity_name = 'DerpTest\\Machinist\\Store\\TestEntity\\Doctrine\\Stuff';
$stuff = $this->em->find($entity_name, $id);
$this->assertEquals('stupid', $stuff->getName());
}
示例7: getIfExist
/**
*
* @param type $id
* @return \Sticks\Model\Stick
* @throws Exceptions\EntityNotFound
*/
public function getIfExist($id)
{
if ($row = $this->_em->find(static::$_stickClass, $id)) {
return $row;
}
throw new Exceptions\EntityNotFound($id);
}
示例8: getObject
private function getObject($object)
{
/** @var ObjectViews $object */
$entity = $this->objects[$object->getEntity()];
$object = $this->em->find($entity, $object->getObjectId());
return $object;
}
示例9: onBuildAfter
/**
* Add required filters
*
* @param BuildAfter $event
*/
public function onBuildAfter(BuildAfter $event)
{
$datagrid = $event->getDatagrid();
/** @var OrmDatasource $ormDataSource */
$ormDataSource = $datagrid->getDatasource();
$queryBuilder = $ormDataSource->getQueryBuilder();
$parameters = $datagrid->getParameters();
if ($parameters->has('userId')) {
$user = $this->entityManager->find('OroUserBundle:User', $parameters->get('userId'));
$queryBuilder->andWhere('call.owner = :user')->setParameter('user', $user);
}
if ($parameters->has('contactId')) {
$contact = $this->entityManager->find('OroCRMContactBundle:Contact', $parameters->get('contactId'));
$queryBuilder->andWhere('call.relatedContact = :contact')->setParameter('contact', $contact);
}
if ($parameters->has('accountId')) {
$account = $this->entityManager->find('OroCRMAccountBundle:Account', $parameters->get('accountId'));
$queryBuilder->andWhere('(call.relatedAccount = :account OR :account MEMBER OF contact.accounts)')->setParameter('account', $account);
}
if ($parameters->has('callIds')) {
$callIds = $parameters->get('callIds');
if (!is_array($callIds)) {
$callIds = explode(',', $callIds);
}
$queryBuilder->andWhere($queryBuilder->expr()->in('call.id', $callIds));
}
}
示例10: addNotification
public function addNotification($users, $notificationType, $notificationDetails)
{
/** @var User $user */
foreach ($users as $user) {
$initiator = null;
$notification = new Notification($notificationType, $user);
$notification->setUserId($user->getId());
if ($notificationType === Notification::SIMPLE_NOTIFICATION) {
$notification->setContent($notificationDetails['content']);
$initiator = "Naidusvoe";
}
if ($notificationType === Notification::CONVERSATION_NOTIFICATION) {
$notification->setConversationId($notificationDetails['conversationId']);
$notification->setMessageId($notificationDetails['messageId']);
$notification->setContent("Ви отримали особисте повідомлення");
$userInitiatorId = $notificationDetails['userInitiatorId'];
$initiator = $this->em->find('NaidusvoeBundle:User', $userInitiatorId)->getUsername();
$notification->setInitiatorId($userInitiatorId);
}
$this->em->persist($notification);
$this->em->flush();
if ($user->getSettings()->getNotificationsEmail()) {
/** @var \Swift_Message $message */
$message = $this->mailer->createMessage()->setSubject('You have some new notification')->setFrom('send@example.com')->setTo($user->getEmail())->setBody($this->templating->render('@Naidusvoe/mail.html.twig', ['content' => $notification->getContent(), 'Initiator' => $initiator]), 'text/html');
$this->mailer->send($message);
}
}
}
示例11: find
/**
* @param string $id Site UUID.
*
* @return Site|null
*/
public function find($id)
{
if (!\Undine\Functions\valid_uuid($id)) {
return null;
}
return $this->em->find(Site::class, (string) $id);
}
示例12: getImageAction
public function getImageAction($id)
{
$image = $this->em->find('HackdayProject\\Entity\\Image', $id);
if (!$image) {
throw new NotFound('Image cannot be found');
}
return new JsonResponse($image->toArray());
}
示例13: findById
/**
* @param int $id
* @return User
* @throws Exception
*/
public function findById($id)
{
$user = $this->entityManager->find('Janus\\ServiceRegistry\\Entity\\User', $id);
if (!$user instanceof User) {
throw new Exception("User '{$id}' not found");
}
return $user;
}
示例14: find
public function find($id)
{
$author = $this->entityManager->find('Doctrine\\Bundle\\LicenseManagerBundle\\Entity\\Author', $id);
if (!$author) {
throw new AuthorNotFoundException($id);
}
return $author;
}
示例15: loginAction
public function loginAction()
{
$this->authSession->Login = null;
$id = $this->getRequest()->getParam("Id");
$login = $this->em->find("eCamp\\Entity\\Login", $id);
$this->authSession->Login = $login;
$this->view->LoginPMod = new eCamp\PMod\LoginPMod($login);
}