我的问题 - 如果我在我的字段 slug 集中创建用户 - 名字+姓氏。如果我更新字段 firstname 和 lastname slug 没有改变,为什么?我需要为这个 trable 检查做什么?因为我在路由中使用 slug 字段(用户名),所以我有:
class SUser implements UserInterface
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @Gedmo\Slug(fields={"firstName", "lastName"}, separator="-")
* @ORM\Column(name="name", type="string", length=255, nullable=false)
* @Assert\Length(min=3, max=255)
*/
protected $username;
我的表格:
class DeveloperPersonalInformationType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('firstname', null, array('label' => 'First Name', 'max_length' => 255, 'required' => false))
->add('lastname', null, array('label' => 'Last Name', 'max_length' => 255, 'required' => false))
现在我使用自定义变体,首先在用户名中设置名字和姓氏结尾,但我想使用@Gedmo\Slug,怎么做?我的行动:
public function submitPersonalInformationAction($username)
{
$em = $this->getDoctrine()->getManager();
$request = $this->get('request');
$profileRepository = $this->get('artel.profile.developer.repository');
$developer = $profileRepository->findOneByUsername($username);
$form = $this->createForm(new DeveloperPersonalInformationType(), $developer);
$form->handleRequest($request);
if ($form->isValid())
{
$name = $developer->getFirstName().'-'.$developer->getLastName();
$developer->setUsername($name);
$em->flush();
return $this->redirect($this->generateUrl('artel_profile_homepage', array('username' => $name)) .'#personal-information');
}
我的轮换:
artel_profile_submit_personal_information:
path: /profile/{username}/personal_information/submit
defaults: { _controller: ArtelProfileBundle:DeveloperProfile:submitPersonalInformation }
requirements: { _method: post }
我的配置:
stof_doctrine_extensions:
default_locale: "%locale%"
orm:
default:
timestampable: true
sluggable: true