Php 如何在edit.html.twig中调用新密码并确认新密码?
我目前正在使用Symfony 2.8进行一个项目。我一直在使用FOSUserBundle配置文件,我不知道“新密码”和“新密码确认”表单的名称。我想在我的edit.html.twig中获取表单变量“newpassword”和“newpasswordconfirmation” 我试过了,但Symfony不认识Php 如何在edit.html.twig中调用新密码并确认新密码?,php,symfony,fosuserbundle,symfony-2.8,Php,Symfony,Fosuserbundle,Symfony 2.8,我目前正在使用Symfony 2.8进行一个项目。我一直在使用FOSUserBundle配置文件,我不知道“新密码”和“新密码确认”表单的名称。我想在我的edit.html.twig中获取表单变量“newpassword”和“newpasswordconfirmation” 我试过了,但Symfony不认识 {% extends "UserBundle::layout.html.twig" %} {% block fos_user_content %} <div class="row cl
{% extends "UserBundle::layout.html.twig" %}
{% block fos_user_content %}
<div class="row clearfix">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="card">
<div class="header">
<h2>
Change Profile
</h2>
</div>
<div class="body">
<form action="{{ path('fos_user_edit') }}" {{ form_enctype(form) }} method="POST" class="fos_user_edit">
{{ form_errors(form) }}
<label for="username">Username</label>
<div class="form-group">
<div class="form-line">
{{ form_widget(form.username, { 'attr': { 'type': 'text', 'id': 'username', 'class': 'form-control', 'placeholder': 'New Username' } }) }}
</div>
</div>
<label for="email">Email</label>
<div class="form-group">
<div class="form-line">
{{ form_widget(form.email, { 'attr': { 'type': 'email', 'class': 'form-control', 'name': 'email', 'placeholder': 'email' } }) }}
</div>
</div>
<label for="password">Current Password</label>
<div class="form-group">
<div class="form-line">
{{ form_widget(form.current_password, { 'attr': { 'type': 'password', 'class': 'form-control', 'name': 'current_password', 'placeholder': 'Current Password' } }) }}
</div>
{{ form_errors(form.current_password) }}
</div>
<label for="new_password">New Password</label>
<div class="form-group">
<div class="form-line">
{{ form_widget(form.new_password, { 'attr': { 'type': 'password', 'class': 'form-control', 'name': 'new_password', 'placeholder': 'New Password' } }) }}
</div>
{{ form_errors(form.new_password) }}
</div>
<label for="new_password_confirmation">Confirm New Password</label>
<div class="form-group">
<div class="form-line">
{{ form_widget(form.new_password_confirmation, { 'attr': { 'type': 'password', 'class': 'form-control', 'name': 'new_password_confirmation', 'placeholder': 'Confirm New Password' } }) }}
</div>
{{ form_errors(form.new_password_confirmation) }}
</div>
<input type="checkbox" id="remember_me" class="filled-in">
<label for="remember_me">Remember Me</label>
<br>
<button type="submit" class="btn btn-primary m-t-15 waves-effect" value="{{ 'profile.edit.submit'|trans({}, 'FOSUserBundle') }}" />UPDATE</button>
{{ form_rest(form) }}
</form>
</div>
</div>
</div>
</div>
{% endblock fos_user_content %}
这是我的控制器:
<?php
namespace UserBundle\Controller;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Bundle\FrameworkBundle\Controller\Controller as ProfController;
class ProfileController extends ProfController
{
public function showAction()
{
$user = $this->container->get('security.context')->getToken()->getUser();
if (!is_object($user) || !$user instanceof UserInterface) {
throw new AccessDeniedException('This user does not have access to this section.');
}
return $this->container->get('templating')->renderResponse('UserBundle:Profile:show.html.'.$this->container->getParameter('fos_user.template.engine'), array('user' => $user));
}
public function editAction()
{
$user = $this->container->get('security.context')->getToken()->getUser();
if (!is_object($user) || !$user instanceof UserInterface) {
throw new AccessDeniedException('This user does not have access to this section.');
}
$form = $this->container->get('fos_user.profile.form');
$formHandler = $this->container->get('fos_user.profile.form.handler');
$process = $formHandler->process($user);
if ($process) {
$this->setFlash('fos_user_success', 'profile.flash.updated');
return new RedirectResponse($this->getRedirectionUrl($user));
}
return $this->container->get('templating')->renderResponse(
'UserBundle:Profile:edit.html.'.$this->container->getParameter('fos_user.template.engine'),
array('form' => $form->createView())
);
}
/**
* Generate the redirection url when editing is completed.
*
* @param \FOS\UserBundle\Model\UserInterface $user
*
* @return string
*/
protected function getRedirectionUrl(UserInterface $user)
{
return $this->container->get('router')->generate('fos_user_profile_show');
}
/**
* @param string $action
* @param string $value
*/
protected function setFlash($action, $value)
{
$this->container->get('session')->getFlashBag()->set($action, $value);
}
}
我很久以前就找到了答案。这是:
{{ form_widget(form.new.first }}
{{ form_errors(form.new.first }}
{{ form_widget(form.new.second }}
{{ form_errors(form.new.second }}
我早就找到了答案。这是:
{{ form_widget(form.new.first }}
{{ form_errors(form.new.first }}
{{ form_widget(form.new.second }}
{{ form_errors(form.new.second }}
{{ form_widget(form.new.first }}
{{ form_errors(form.new.first }}
{{ form_widget(form.new.second }}
{{ form_errors(form.new.second }}