本文整理汇总了PHP中Doctrine\ORM\Query::setParameter方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::setParameter方法的具体用法?PHP Query::setParameter怎么用?PHP Query::setParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Query
的用法示例。
在下文中一共展示了Query::setParameter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: consultaContiene
/**
* @param \Doctrine\ORM\Query|\Doctrine\ORM\QueryBuilder $query
* @param array $array
* @param string $contiene
* @return \Doctrine\ORM\Query|\Doctrine\ORM\QueryBuilder
*/
public function consultaContiene($query, $array, $contiene)
{
if ($contiene != "") {
$fields = array_keys($this->getClassMetadata()->fieldNames);
$alias = $query->getRootAlias();
$count = 0;
foreach ($array as $field) {
$fieldMapping = $this->getClassMetadata()->getFieldForColumn($field);
$where = sprintf("UPPER(%s.%s) LIKE :condicion", $alias, $fieldMapping);
if ($count == 0) {
$query->andWhere($where);
} else {
$query->orWhere($where);
}
$count++;
}
$query->setParameter("condicion", "%" . strtoupper($contiene) . "%");
}
return $query;
}
示例2: testApplyAnonymous
/**
* @covers Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper::apply
* @covers Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper::cloneQuery
*/
public function testApplyAnonymous()
{
/* @var $queryBuilder QueryBuilder */
$queryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
$query = new Query($this->em);
$query->setParameter('paramName', 'paramValue', 'paramType');
$queryBuilder->expects($this->any())->method('getQuery')->will($this->returnValue($query));
$queryBuilder->expects($this->once())->method('getRootEntities')->will($this->returnValue(array('Kunstmaan\\NodeBundle\\Entity\\Node')));
$queryBuilder->expects($this->once())->method('getRootAliases')->will($this->returnValue(array('n')));
$roles = array();
$this->token->expects($this->once())->method('getRoles')->will($this->returnValue($roles));
$this->rh->expects($this->once())->method('getReachableRoles')->with($roles)->will($this->returnValue($roles));
$this->token->expects($this->any())->method('getUser')->will($this->returnValue('anon.'));
$permissionDef = new PermissionDefinition(array('view'), 'Kunstmaan\\NodeBundle\\Entity\\Node');
/* @var $query Query */
$query = $this->object->apply($queryBuilder, $permissionDef);
$this->assertEquals(MaskBuilder::MASK_VIEW, $query->getHint('acl.mask'));
$this->assertEquals($permissionDef->getEntity(), $query->getHint('acl.root.entity'));
$this->assertEquals('rootTable', $query->getHint('acl.entityRootTableName'));
$this->assertEquals('n', $query->getHint('acl.entityRootTableDqlAlias'));
$aclQuery = $query->getHint('acl.extra.query');
$this->assertContains('"IS_AUTHENTICATED_ANONYMOUSLY"', $aclQuery);
}
示例3: findCollectionBreadcrumbById
/**
* {@inheritdoc}
*/
public function findCollectionBreadcrumbById($id)
{
try {
$sql = sprintf('SELECT n, collectionMeta, defaultMeta
FROM %s AS p,
%s AS n
LEFT JOIN n.meta AS collectionMeta
LEFT JOIN n.defaultMeta AS defaultMeta
WHERE p.id = :id AND p.lft > n.lft AND p.rgt < n.rgt
ORDER BY n.lft', $this->_entityName, $this->_entityName);
$query = new Query($this->_em);
$query->setDQL($sql);
$query->setParameter('id', $id);
return $query->getResult();
} catch (NoResultException $ex) {
return [];
}
}
示例4: setParameters
/**
* Sets parameters for the query
*
* @param \Doctrine\ORM\Query $query Query to be set parameters on
* @param array $parameters Variables
*
* @return \Doctrine\ORM\Query
*
* @author r1pp3rj4ck <attila.bukor@gmail.com>
*/
private function setParameters(\Doctrine\ORM\Query $query, array $parameters)
{
foreach ($parameters as $name => $param) {
$query->setParameter($name, $param['value']);
}
return $query;
}
示例5: testStaticApply
public function testStaticApply()
{
$staticSegmentStub = new Segment();
$staticSegmentStub->setType(new SegmentType(SegmentType::TYPE_STATIC));
$filterData = ['value' => $staticSegmentStub];
$subquery = 'SELECT ts1.entity_id FROM OroSegmentBundle:SegmentSnapshot ts1 WHERE ts1.segmentId = :segment';
$em = $this->getTestEntityManager();
$qb = new QueryBuilder($em);
$qb->select(['t1.name'])->from('OroSegmentBundle:CmsUser', 't1');
$ds = new OrmFilterDatasourceAdapter($qb);
$query = new Query($em);
$query->setDQL($subquery);
$query->setParameter('segment', $staticSegmentStub);
$this->staticSegmentQueryBuilder->expects($this->once())->method('build')->with($staticSegmentStub)->will($this->returnValue($query));
$this->filter->init('someName', [FilterUtility::DATA_NAME_KEY => self::TEST_FIELD_NAME]);
$this->filter->apply($ds, $filterData);
$expectedResult = ['SELECT t1.name FROM OroSegmentBundle:CmsUser t1 WHERE t1.id', 'IN(SELECT ts1.entity_id FROM OroSegmentBundle:SegmentSnapshot ts1 WHERE ts1.segmentId = :segment)'];
$expectedResult = implode(' ', $expectedResult);
$this->assertEquals($expectedResult, $ds->getQueryBuilder()->getDQL());
$params = $ds->getQueryBuilder()->getParameters();
$this->assertCount(1, $params, 'Should pass params to main query builder');
$this->assertEquals($staticSegmentStub, $params[0]->getValue());
}
示例6: param
/**
* Sets params value in a query object
*
* @access public
* @param string $sParamName
* @param string $mParamValue
* @return $this
* @since 1.0.0-alpha
* @version 1.0.0-alpha
*/
public function param($sParamName, $mParamValue)
{
$this->oQuery->setParameter($sParamName, $mParamValue);
return $this;
}
示例7: testCacheMissWhenTypeChanges
/**
* @depends testIssue
*/
public function testCacheMissWhenTypeChanges(Query $query)
{
$query->setParameter('field', 'test', 'string');
$this->assertStringEndsWith('.field = ?', $query->getSQL());
}
示例8: tagAction
/**
* @route: blog_tag
* Tag Controller
*/
public function tagAction($slug)
{
$em = $this->getEm();
$query = new Query($em);
$query->setDQL(
'SELECT t
FROM Bundle\BlogBundle\Entity\Tag t WHERE t.slug = ?1'
);
$query->setParameter(1, $slug);
$tag = $query->getSingleResult();
return $this->render('BlogBundle:Blog:tag.html.twig', array(
'tag' => $tag,
'posts' => $tag->getPosts()
));
}