使用dql我试图检查实体是否是集合子实体的成员
product
customer
customer.orders (collection)
customer.orders.products (collection, type: product)
customer.cancellations.productContainers (collection)
customer.cancellations.productContainers.product (entity, type: product)
Run Code Online (Sandbox Code Playgroud)
客户有多个订单.订单有多个产品.客户有多次取消.取消有多个productContainers.productContainer有一个产品.
我想获得所有未被取消的订购产品.
$qb->select('c, d, p')
->from('XyzBundle:Customer', 'c')
->leftJoin('c.orders', 'co')
->leftJoin('co.products', 'cop')
->leftJoin('c.cancellation', 'ca')
->leftJoin('ca.productContainers', 'cap')
->leftJoin('cap.product', 'capp')
->andWhere('cop NOT MEMBER OF capp')
Run Code Online (Sandbox Code Playgroud)
但是这不起作用,因为ca.productContainers是集合字段而不是它的supentity ca.productContainers.product.因此我收到以下错误:
CRITICAL - Uncaught PHP Exception Doctrine\ORM\Query\QueryException:
"[Semantical Error] line 0, col 414 near 'product': Error: Invalid PathExpression.
Must be a CollectionValuedAssociationField." at
/vagrant/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php line 4 9
Run Code Online (Sandbox Code Playgroud)
有什么建议如何解决这个问题?
我使用安全选民作为symfony的acl系统的替代品.
我的选民看起来很像以下一个.
class FoobarVoter implements VoterInterface
{
public function supportsClass($class)
{
return in_array($class, array(
'Example\FoobarBundle\Entity\Foobar',
));
}
public function supportsAttribute($attribute)
{
return in_array(strtolower($attribute), array('foo', 'bar'));
}
public function vote(TokenInterface $token, $object, array $attributes)
{
$result = VoterInterface::ACCESS_ABSTAIN
if (!$this->supportsClass(get_class($object))) {
return VoterInterface::ACCESS_ABSTAIN;
}
foreach ($attributes as $attribute) {
$attribute = strtolower($attribute);
// skip not supported attributes
if (!$this->supportsAttribute($attribute)) {
continue;
}
[... some logic ...]
}
return $result;
}
}
Run Code Online (Sandbox Code Playgroud)
我的选民被包括在内并在每个页面加载时调用.即使他们不支持给定班级的决定. FoobarVoter::vote()总是被称为.即使 …
我gethostbyname()用来获取应用程序中域的IP地址.
在某些情况下,也检查无效地址,如'50 .9.49'.
echo gethostbyname('50.9.49'); // returns 50.9.0.49
Run Code Online (Sandbox Code Playgroud)
在这种情况下gethostbyname应该返回false或未修改的无效IP地址.但是这些函数返回修改后的IP地址50.9.0.49.
看起来像PHP中的错误.快速解决方案似乎是检查无效的数字地址之前,还有其他建议吗?
在symfony2应用程序中,实体Message与文档具有一对多的关系.文档表示用户上传.我创建了一个表单.我意识到两种形式:MessageForm和DocumentForm.DocumentForm位于MessageForm中的集合FormField中.上传和处理文件确实有效.
但是,如果我想编辑实体消息,则表单包含与存在的文档一样多的空FileInput.期望的行为是:
这应该在表单内处理.提交表单时应进行更改.
怎么能实现呢?