0
我遇到了登錄問題。我已經閱讀了symfony doc。,主題在stackoverflow和其他教程。當我嘗試使用Firefox或Chrome登錄時,我第一次不會登錄,但是第二次嘗試成功。在IE中我根本不會登錄。你可以幫忙嗎?我沒有想法。這裏是我的代碼:Symfony簡單登錄表單問題
index.html.twig
<form action="{{ path('login_check') }}" method="post">
<input type="text" id="username" name="_username" placeholder="{{ 'INDEX_LOGIN_USERNAME'|trans }}" />
<input type="password" id="password" name="_password" placeholder="{{ 'INDEX_LOGIN_PASSWORD'|trans }}" />
{#<input type="hidden" name="_target_path" value="/admin" />#}
<button type="submit"></button>
</form>
的routing.yml
login:
path: /login
// without next line (defaults) I receive an error: Unable to find the controller for path "/login". The route is wrongly configured.
defaults: { _controller: FC_Hlinsko_Bundle:Default:index }
options: { i18n: false }
logout:
path: /logout
options: { i18n: false }
homepage:
path: /
defaults: { _controller: FC_Hlinsko_Bundle:Default:index }
admin:
path: /admin
defaults: { _controller: FC_Hlinsko_Bundle:Admin:index }
security.yml
security:
providers:
in_memory:
memory:
users:
admin:
password: $2y$12$aE7n0XduDqfYd5xZVfm.G.uiIZSMUCdtPxfz6VRgdBKrU2ihxcC7i
roles: 'ROLE_ADMIN'
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
anonymous: true
secured_area:
pattern: ^/
form_login:
check_path: /login_check
login_path: login
logout:
path: logout
target: homepage
anonymous: ~
access_control:
# require ROLE_ADMIN for /admin*
- { path: /login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: /admin, roles: ROLE_ADMIN }
encoders:
Symfony\Component\Security\Core\User\User:
algorithm: bcrypt
cost: 12
請提供FC_Hlinsko_Bundle /Controllers/DefaultController.php indexAction方法。看起來像你對每個前端請求使用相同的控制器方法。這是一個錯誤的方式。你應該有單獨的方法主頁,登錄,註銷 –
'公共功能indexAction(Request $ request) { return $ this-> render('FC_Hlinsko_Bundle:Default:index.html.twig'); }' }只是呈現index.html.twig ... 這是因爲我有隱藏在index.html.twig中的登錄表單,它出現在登錄鏈接 – Pesino
相同就像他們在這裏[link](http ://www.fcviktoria.cz/eng/)..網站頂部的SIGN IN鏈接:-) – Pesino