小编aus*_*usi的帖子

doctrine2使用过多的SQL查询加载与获取模式一对多的关联

我正在加载许多实体的列表.
这些实体与其他实体具有一对多关联.
我想在一个SQL查询中加载所有这些其他实体(而不是对第一个列表中的每个实体进行一次查询).

如doctrine2文档中所述:http://www.doctrine-project.org/docs/orm/2.1/en/reference/dql-doctrine-query-language.html#temporarily-change-fetch-mode-in-dql这应该可以通过"EAGER"加载来实现.

但它没有按照描述的那样工作.

我的代码:

class User{
    /**
     * @ORM\OneToMany(targetEntity="Address", mappedBy="user", indexBy="id", fetch="EAGER")
     */
    protected $addresses;
    public function __construct(){
        $this->addresses = new ArrayCollection();
    }
}

class Address{
    /**
     * @ORM\ManyToOne(targetEntity="User", inversedBy="addresses")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="UserId", referencedColumnName="id")
     * })
     */
    private $user;
}

class UserRepository{
    public function findUsersWithAddresses(){
        return $this->getEntityManager()
            ->createQuery('SELECT u FROM MyBundle:User u ORDER BY u.name ASC')
            ->setFetchMode('MyBundle\Entity\User', 'addresses', \Doctrine\ORM\Mapping\ClassMetadata::FETCH_EAGER)
            ->setMaxResults(10)
            ->getResult();
    }
}
Run Code Online (Sandbox Code Playgroud)

UserRepository :: findUsersWithAddresses()方法执行11个SQL查询.

如何告诉Doctrine只使用一个SQL查询来加载地址实体?

我在用:

  • symfony v2.0.9
  • 学说共同的2.1.4
  • 学说 - …

php doctrine symfony doctrine-orm

18
推荐指数
2
解决办法
3万
查看次数

iOS需要双击一个简单的链接元素

如果您点击iOS上的元素,浏览器将触发mouseover/mousemove事件并呈现:hover样式.如果在此过程中检测到"内容更改",则不会触发任何点击事件,您必须再次点击才能触发点击事件.这在developer.apple.com上有记录.

即使没有:hover应用任何鼠标事件或样式,我在网页上遇到了检测到"内容更改"的问题.花了一段时间,但我能够将网页缩小到一个小测试用例:

<style>
    a:hover { color: red }
    foo + * { color: red }
</style>
<a href="about:blank">foo</a>
<input type="search">
Run Code Online (Sandbox Code Playgroud)

在此页面上,您必须在"foo"链接上点击两次才能导航.使用iPad mini和iPhone(原生和模拟器)进行测试.

之后我发现这篇博文有类似的问题.但唯一适用于我的问题的解决方案是以下CSS:

input[type=search]::-webkit-search-cancel-button {
    display: none;
}
Run Code Online (Sandbox Code Playgroud)

但如果我希望搜索取消按钮可见,我无法使用此解决方法.

这个问题还有其他解决方法吗?

几天前我在bugreport.apple.com上发布了这个bug,直到现在还没有苹果的反应.这个bug似乎是在iOS 6和7中,如果它有一天得到修复它会很棒.

如何确定这是webkit还是iOS错误?

报告此错误的正确位置在哪里?


UPDATE

此错误似乎在iOS 8中得到修复.使用iPad mini和iPhone(本机和模拟器)进行测试.

更新2

在iOS 8中没有完全修复Bug,如果你在大括号之间插入一些CSS,它仍会出现,例如color: red.我更新了测试用例以在iOS 8中显示错误.

更新3

这个bug在iOS 9中没有修复,除了"按预期行为"之外,仍然没有来自bugreport.apple.com的反应.

html css mobile-safari touch ios

16
推荐指数
1
解决办法
6350
查看次数

在Symfony2中创建组合的客户端和服务器端验证

我认为在symfony2 FormValidator组件上创建客户端表单验证非常有用.

执行此操作的最佳方法是将验证约束传递给表单视图.有了这些信息,就可以制作一个模板,将表单字段呈现为:

<div>
    <label for="form_email">E-Mail</label>
    <input 
        id="form_email" type="text" name="form[email]" value=""
        data-validation-constraints='{"NotBlank":{},"MinLength":{"limit":6}}'
    />
</div>
Run Code Online (Sandbox Code Playgroud)

然后,JavaScript部分将查找<input>具有该data-validation-constraints属性的所有元素并为它们创建正确的验证.

要将验证约束传递给表单视图,我认为最好的方法是创建表单类型扩展.这就是我的问题:这是正确的方法吗?这怎么可能?

在片刻,我的表单类型扩展如下所示:

use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormBuilder;

class FieldTypeExtension extends \Symfony\Component\Form\AbstractTypeExtension{

    public function getExtendedType(){
        return 'field';
    }

    public function buildView(FormView $view, FormInterface $form)
    {
        // at this point i didn't find a way to get the 
        // validation constraints out of the $form
        // the `getAllValidationConstraints` here is just an example
        $view->set('validation_constraints', $form->getAllValidationConstraints());
    }

}
Run Code Online (Sandbox Code Playgroud)

如何从FormInterface对象中获取应用于一个表单字段的所有验证约束?

php validation symfony-forms symfony

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

Incorrect value type "@context" in Google Rich Results Test

Im pretty new to JSON-LD and am currently struggling making the Google Rich Results Test happy with my custom JSON-LD data.

Every time I use a @context other than https://schema.org/ it shows me the error Incorrect value type "@context".

This even happens with this simple example based on a json-ld.org context:

<script type="application/ld+json">
{
  "@context": "https://json-ld.org/contexts/person.jsonld",
  "@type": "Person",
  "name": "Foo"
}
</script>
Run Code Online (Sandbox Code Playgroud)

Rich Results Test Error

After some trail and error I found out that with the following code the json-ld.org/playground shows me …

json-ld google-rich-snippets

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