小编use*_*165的帖子

如何从symfony表单处理程序中的表单中删除空值字段

我想在两个条件下更新数据:

  1. 当用户输入表单中的所有字段时(姓名,电子邮件,密码)
  2. 当用户没有输入密码时(我只需要更新姓名和电子邮件).

我有以下formHandler方法.

public function process(UserInterface $user)
{
    $this->form->setData($user);

    if ('POST' === $this->request->getMethod()) {                       

        $password = trim($this->request->get('fos_user_profile_form')['password']) ;
        // Checked where password is empty
        // But when I remove the password field, it doesn't update anything.
        if(empty($password))
        {
            $this->form->remove('password');            
        }

        $this->form->bind($this->request);

        if ($this->form->isValid()) {
            $this->onSuccess($user);

            return true;
        }

        // Reloads the user to reset its username. This is needed when the
        // username or password have been changed to avoid issues with the
        // security layer.
        $this->userManager->reloadUser($user); …
Run Code Online (Sandbox Code Playgroud)

symfony-forms symfony

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

如何根据树枝模板中的 Symfony 用户角色显示任何包含的模板

我有以下模板代码。

<div class="row">
   {% include 'ProductBundle:Partials:productInfo.html.twig' %}

   {% include 'OrderBundle:Partials:orderInfo.html.twig' %}

   {% include 'DeliveryBundle:Partials:deliveryInfo.html.twig' %}

   {% include 'BillBundle:Partials:billInfo.html.twig' %}
</div>
Run Code Online (Sandbox Code Playgroud)

我想展示ROLE_USER. 他无法访问其他三个包括。其他用户ROLE_ADMIN可以访问所有四个包含部分。

有没有办法用树枝做到这一点?

roles symfony twig

0
推荐指数
1
解决办法
199
查看次数

标签 统计

symfony ×2

roles ×1

symfony-forms ×1

twig ×1