這裏的第一個問題。 我正在開發一個登錄頁面,我無法弄清楚爲什麼我的登錄表單顯示兩次。我仔細檢查了樹枝文件和路線,我沒有看到可能導致它的原因。Symfony應用程序,內容顯示兩次
我使用的是PHP服務器,所以我在開發環境中,我認爲發生的事情是我的調試欄被實際頁面替換,導致顯示內容兩次。調試器欄未顯示。我在谷歌搜索,我看到他們提到有關身體標記未關閉的東西,所以我也檢查了。仍然注意到。我檢查了是否有其他文件也在調用登錄模板。沒有...任何建議?
這是一張圖片,它的價值超過一千字。
感謝
image shows the login page showing twice
另外,這裏是我使用的代碼,這是直接從symfony的文檔:
控制器
/**
* @Route("/login", name="security_login")
*/
public function loginAction(Request $request)
{
$authenticationUtils = $this->get('security.authentication_utils');
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', array(
'last_username' => $lastUsername,
'error' => $error,
));
}
Securit.yml
providers:
app_user_prov:
entity:
class: AppBundle:User
firewalls:
main:
pattern: ^/
anonymous: ~
guard:
authenticators:
- cas_authenticator
登錄樹枝文件:
{% extends 'base.html.twig' %}
{% block content %}
{% if error %}
<div class="row">
<div class="col-lg-12">
<p class="bg-danger">{{ error.messageKey|trans(error.messageData, 'security') }}</p>
</div>
</div>
{% endif %}
<div class="row">
<div class="col-lg-12 text-center" style="margin-top:35px;">
<img style="border:none;" src="loreipsum.png" width="200">
<br /> <br />
<form action="{{ path("security_login") }}" method="post" style="margin-top:15px;">
<div class="form-group">
<label for="username">Username or email</label>
<input type="text" id="username" name="_username" value="{{ last_username }}" required="required" />
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="_password" required="required" />
</div>
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
<div class="form-group">
<input type="submit" id="_submit" name="_submit" value="Submit" />
</div>
</form>
</div>
</div>
{% endblock %}
基地樹枝文件:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}Administration{% endblock %}</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymo
{% block stylesheets %}{% endblock %}
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
<!-- jQuery and Bootstrap -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
{% block javascripts %}{% endblock %}
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-6">
<h1 class="text-left">
<img style="border:none;" src="loremipsum.jpg" width="200">
</h1>
</div>
<div class="col-lg-6">
<h3 class="text-right"> <br/>Lorem ipsum</h3>
</div>
</div>
{% block content %}{% endblock %}
</div>
</body>
</html>
請提供我們一些代碼 – DFayet
代碼實際上來自symfony的文檔。相同的結構,相同的代碼 – CookieMonster
請向我們展示base.html.twig。 – DFayet