小编Mar*_*ham的帖子

doctrine2关于集合子实体的dql成员

使用dql我试图检查实体是否是集合子实体的成员

entites的:

       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)

有什么建议如何解决这个问题?

dql doctrine-orm

14
推荐指数
1
解决办法
895
查看次数

为什么总是打电话给symfony2安全选民?

我使用安全选民作为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)

问题:

减少对Voter :: vote()的调用

我的选民被包括在内并在每个页面加载时调用.即使他们不支持给定班级的决定. FoobarVoter::vote()总是被称为.即使 …

php security performance symfony

7
推荐指数
1
解决办法
2164
查看次数

PHP:gethostbyname错误

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中的错误.快速解决方案似乎是检查无效的数字地址之前,还有其他建议吗?

php ip gethostbyname

6
推荐指数
1
解决办法
1162
查看次数

如何使用symfony2中的FileType输入处理编辑表单

在symfony2应用程序中,实体Message与文档具有一对多的关系.文档表示用户上传.我创建了一个表单.我意识到两种形式:MessageForm和DocumentForm.DocumentForm位于MessageForm中的集合FormField中.上传和处理文件确实有效.

但是,如果我想编辑实体消息,则表单包含与存在的文档一样多的空FileInput.期望的行为是:

  • FileInputs上传新文件
  • 文件名(链接)到现有文件
  • 删除现有文件的可能性

这应该在表单内处理.提交表单时应进行更改.

怎么能实现呢?

php forms symfony

3
推荐指数
1
解决办法
7328
查看次数

标签 统计

php ×3

symfony ×2

doctrine-orm ×1

dql ×1

forms ×1

gethostbyname ×1

ip ×1

performance ×1

security ×1