小编Rod*_*olz的帖子

Symfony2 $ user-> setPassword()将密码更新为纯文本[DataFixtures + FOSUserBundle]

我正在尝试使用一些User对象预先填充数据库,但是当我调用$user->setPassword('some-password');然后保存用户对象时,字符串'some-password'直接存储在数据库中,而不是散列+ salted密码.

我的DataFixture类:

// Acme/SecurityBundle/DataFixtures/ORM/LoadUserData.php
<?php

namespace Acme\SecurityBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

use Acme\SecurityBundle\Entity\User;

class LoadUserData implements FixtureInterface
{
    public function load(ObjectManager $manager)
    {
        $userAdmin = new User();
        $userAdmin->setUsername('System');
        $userAdmin->setEmail('system@example.com');
        $userAdmin->setPassword('test');

        $manager->persist($userAdmin);
        $manager->flush();
    }
}
Run Code Online (Sandbox Code Playgroud)

以及相关的数据库输出:

id  username    email               salt                                password
1   System      system@example.com  3f92m2tqa2kg8cookg84s4sow80880g     test
Run Code Online (Sandbox Code Playgroud)

php doctrine symfony fosuserbundle

44
推荐指数
4
解决办法
4万
查看次数

Elixir - 拆分一个字符串,使其不返回列表中的空字符串?

我在正则表达式上拆分字符串.结果数组包含正则表达式匹配的空字符串.我不想要那些.例如,

iex(1)> String.split("Hello world. How are you?", ~r/\W/)
["Hello", "world", "", "How", "are", "you", ""]
Run Code Online (Sandbox Code Playgroud)

如何拆分字符串以便它不会在列表中返回空字符串?

elixir

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

Bevy 如何根据参数的类型“范围”其系统?

Bevy是一个新的 Rust 游戏引擎和 ECS,它有一个功能,它根据参数的类型“确定”其系统。从它的文档

我们传递给“系统函数”的参数定义了系统在哪些实体上运行。在这种情况下,greet_people 将在具有 Person 和 Name 组件的所有实体上运行。

它看起来像这样:

struct Person;
struct Name(String);

fn greet_people(person: &Person, name: &Name) {
    println!("hello {}", name.0);
}
Run Code Online (Sandbox Code Playgroud)

Bevy 是如何做到这一点的?我以为我在某处读到 Rust 不支持这种方式的反射。

rust bevy

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

Symfony 2 - 表单选择选项数据库

我是Symfony 2的初学者.

我正在尝试显示带有"选择"的表单,其中是查询中的"选项".

我把以下代码放在我的表单中:

use Doctrine\ORM\EntityRepository;
use Bloc\MainBundle\Entity\Table;
use Bloc\MainBundle\Entity\Table2;

public function addAction(Request $request)
{
    $table = new Table();
    $form = $this->createFormBuilder($table , array('attr' => array('role' => 'form')))
        ->add('num', 'integer', array('label' => 'Numéro', 'attr' => array('class' => 'form-control')))
        ->add('nom_emetteur', 'text', array('label' => 'Emetteur', 'attr' => array('class' => 'form-control')))
        ->add('numero', 'entity', array('class' => 'BlocMainBundle:Table2', 'property' => 'numero'))
        ...
}
Run Code Online (Sandbox Code Playgroud)

我有以下错误:

Neither the property "numero" nor one of the methods "getNumero()", "isNumero()", "hasNumero()", "__get()" or "__call()" exist and have public access in …
Run Code Online (Sandbox Code Playgroud)

symfony doctrine-orm

4
推荐指数
1
解决办法
1万
查看次数

Django Haystack - 如何在没有词干的情况下强制精确的属性匹配?

我将 Django 1.5 与 django-haystack 2.0 和 elasticsearch 后端一起使用。我正在尝试通过精确的属性匹配进行搜索。但是,即使我同时使用__exact运算符和 Exact() 类,我也得到了“类似”的结果。我怎样才能防止这种行为?

例如:

# models.py
class Person(models.Model):
    name = models.TextField()


# search_indexes.py
class PersonIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    name = indexes.CharField(model_attr="name")

    def get_model(self):
        return Person

    def index_queryset(self, using=None):
        return self.get_model().objects.all()


# templates/search/indexes/people/person_text.txt
{{ object.name }}


>>> p1 = Person(name="Simon")
>>> p1.save()
>>> p2 = Person(name="Simons")
>>> p2.save()

$ ./manage.py rebuild_index

>>> person_sqs = SearchQuerySet().models(Person)
>>> person_sqs.filter(name__exact="Simons")
[<SearchResult: people.person (name=u'Simon')>
 <SearchResult: people.person (name=u'Simons')>]
>>> person_sqs.filter(name=Exact("Simons", clean=True))
[<SearchResult: people.person (name=u'Simon')> …
Run Code Online (Sandbox Code Playgroud)

django django-haystack elasticsearch

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