小编lif*_*ifo的帖子

使用bootstrap + font-awesome减少CSS"别名"

我的网站使用bootstrap+ font-awesome,我正在尝试在我的site.less文件中创建一个"别名" :

.icon-domain { .icon-fire; }
.icon-group  { .icon-tags; }
Run Code Online (Sandbox Code Playgroud)

我这样做的原因是因为我的网站上有一个"域"实体,我可能会在将来更改图标,所以我不想直接使用HTML中的"fire"图标.

icon-group类的工作对我的代码,但icon-domain没有.从我所知道的,因为font-awesome实际上icon-group在其代码中有一个类.根据我的理解,lesscss我可以在另一个类中包含一个类,将它们组合成一个新类,但它根本就不能在这里工作.

如果我这样做,我可以让它工作site.less:

.icon-domain { &:before { content: "\f06d"; } }
Run Code Online (Sandbox Code Playgroud)

但这并不理想,因为我必须自己定义内容并使用.icon-domain { .icon-fire; &:before; }语法错误.反正有没有使这项工作正常?

less twitter-bootstrap font-awesome

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

不带主 ID 密钥的 Doctrine ManyToOne

我正在尝试在数据库中的两个实体之间设置 FK。父表与子表具有多对一关系。我无法使用正常的parent_id => id FK 连接这些表,因为子表是由外部进程填充的(父表永远不知道子表的主ID)。

Doctrine 接受如下所示的实体,但 Mysql 在尝试将 FK 添加到表时失败,并出现以下错误。

ALTER TABLE parent_tbl ADD CONSTRAINT FK_1172A832F85E0677 FOREIGN KEY (username) REFERENCES child_tbl (username);

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`dmname`.`#sql-f16_d8acf`, CONSTRAINT `FK_1172A832F85E0677` FOREIGN KEY (`username`) REFERENCES `child_tbl` (`username`))

class Parent
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;


    /**
     * @ORM\ManyToOne(targetEntity="Child")
     * @ORM\JoinColumn(name="username", referencedColumnName="username", nullable=false)
     */
    protected $username;

    // ...
}

class Child
{
    /** …
Run Code Online (Sandbox Code Playgroud)

doctrine symfony doctrine-orm

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

在EventListener中添加表单错误

我有一个基于Symfony 2.2的应用程序,其表单的字段只需要基于表单中的另一个字段.我绑定了一个EventListener来捕获表单的提交时间,这样我就可以验证提交表单时是否真的不需要'required'字段.

我注意到我无法FormErrorPRE_BIND表单事件中设置内容.这样做不会显示错误,但是如果我绑定到BIND事件监听器,那么表单错误会正确显示但我不想等到BIND事件检查我的错误(我不希望潜在的坏数据绑定到我的实体).

有人能告诉我为什么会这样吗?

public function buildForm(FormBuilderInterface $builder, array $options)
{
    // snip ...

    $builder->addEventListener(FormEvents::PRE_BIND, function(FormEvent $event) use ($options) {
        $data = $event->getData();
        $form = $event->getForm();
        if ($data === null) {
            return;
        }

        // yes, this is definitely called; If I remove the if() and just
        // and just add the formError it still doesn't work.
        if ($data['type'] == 'port' and empty($data['protocol'])) {
            $form->get('protocol')->addError(new FormError('A valid protocol must be selected.'));
        }

    });

}
Run Code Online (Sandbox Code Playgroud)

php symfony symfony-2.2

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