Я не могу понять, почему я не могу войти.Symfony2, не в состоянии войти, может быть, причина в переводе?
Я получаю сообщение об ошибке «Контроллер должен вернуть ответ (нулевое значение). Забыл ли вы добавить оператор возврата где-нибудь в вашем контроллере?»
(и печать сообщения от SecurityController если я раскомментировать, loginCheckAction (маршрут sec_login_check), который, насколько я понимаю, никогда не должен быть напечатан (= выполняется).
Я извлекал перевод, удалены любые префиксы (например, безопасности) от маршрута входа и создал новый проект. тем не менее, я все еще получаю эту ошибку.
// C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\sym\demo\src\Demo\DemoBundle\Controller\SecurityController.php
<?php
namespace Demo\DemoBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Demo\DemoBundle\Entity\User;
/**
* Class SecurityController
*
* @Route("/security")
* @package Demo\DemoBundle\\Controller
*/
class SecurityController extends Controller {
/**
* @Route("/login", name="sec_login_form")
* @Template("DemoDemoBundle:Security:login.html.twig")
* @Method("GET|POST")
*/
public function loginAction()
{
$auth_checker = $this->get('security.authorization_checker');
if ($auth_checker->isGranted('IS_AUTHENTICATED_ANONYMOUSLY')
&& !($auth_checker->isGranted('ROLE_USER') || $auth_checker->isGranted('ROLE_ADMIN') )
) {
$authenticationUtils = $this->get('security.authentication_utils');
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render (
'DemoDemoBundle:Security:login.html.twig' ,
array(
'last_username' => $lastUsername,
'error' => $error,
));
}
else {
return $this->render(
'DemoDemoBundle:Default:index.html.twig',
array('msg' => "You are already logged in!",)); //case of bundle
}
}
/**
* @Route("/login_check", name="sec_login_check")
*/
public function loginCheckAction() {
//print_r(" there is something wrong with the firewall if you see this :loginCheckAction, route name sec_login_check");
}
/**
* @Route("/logout", name="sec_logout")
*/
public function logoutAction() {}
}
// C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\sym\demo\app\config\security.yml security:
encoders:
Demo\DemoBundle\Entity\User: sha512
providers:
database_users:
entity:
class: DemoDemoBundle:User
property: username
role_hierarchy:
ROLE_AUTHOR: [ROLE_USER]
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
secured_area:
pattern: ^/ , but it gives the same error
#also used pattern: ^/security/ but it gives the same error
provider: database_users
anonymous: ~
access_denied_url: /security/login
form_login:
check_path: sec_login_check
login_path: sec_login_form
logout:
path: sec_logout
target: event_index
access_control:
#i have used only one case from below at a time:
#case 1 gives the error: The controller must return a response (null given)
- { path: ^/security/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: ROLE_USER }
#case 2 gives the error: The controller must return a response (null given)
- { path: ^/security/login$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: ROLE_USER }
#case 3 gives the error: The controller must return a response (null given)
- { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
// C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\sym\demo\app\config\routing.yml
demo_demo_security:
resource: "@DemoDemoBundle/Controller/SecurityController.php"
type: annotation
prefix: /
sec_login_form:
path: /security/login
defaults: { _controller: 'DemoDemoBundle:Security:login' }
options: { compiler_class: Symfony\Component\Routing\RouteCompiler }
methods: [POST, GET]
sec_login_check:
path: /security/login_check
defaults: { _controller: 'DemoDemoBundle:Security:loginCheck' }
options: { compiler_class: Symfony\Component\Routing\RouteCompiler }
methods: [POST, GET]
sec_logout:
path: /security/logout
defaults: { _controller: 'DemoDemoBundle:Security:logout' }
options: { compiler_class: Symfony\Component\Routing\RouteCompiler }
**************** Это вопрос я попросил две недели раньше.
(я удалил конфигурацию перевода и {_trans} из маршрутизации, но все-таки получил ошибку выше. В начале я бродил, возможно, причина в том, что переводчик? Как настроить логин, если я использую |trans
в веточке . шаблон
sym\just2\app\config\routing.yml
sec_login_form:
path: /security/login
defaults: { _controller: 'MeetingBundle:Security:login' }
options: { compiler_class: Symfony\Component\Routing\RouteCompiler }
methods: [POST, GET]
sec_login_check:
path: /security/login_check
defaults: { _controller: 'MeetingBundle:Security:loginCheck' }
options: { compiler_class: Symfony\Component\Routing\RouteCompiler }
methods: [POST, GET]
sec_logout:
path: /security/logout
defaults: { _controller: 'MeetingBundle:Security:logout' }
options: { compiler_class: Symfony\Component\Routing\RouteCompiler }
C: \ Bitnami \ wampstack-5.6.20-0 \ apache2 \ HTDOCS \ SYM \ Just2 \ приложение \ Config \ security.yml
security:
encoders:
MeetingBundle\Entity\User: sha512
providers:
database_users:
entity: { class: MeetingBundle:User }
role_hierarchy:
ROLE_AUTHOR: [ROLE_USER]
ROLE_ADMIN: [ROLE_ADMIN]
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
secured_area:
pattern: ^/
provider: database_users
anonymous: true
access_denied_url: /security/login
form_login:
check_path: /security/login_check
# did not work either: sec_login_check
login_path: /security/login
# did not work either: sec_login_form
default_target_path: event_index
always_use_default_target_path: true
logout:
path: /security/logout
# did not work either: sec_logout
target: event_index
access_control:
- { path: ^/security/login_check$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/security/login$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/event/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/evcom/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/security/regist1$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/security/remind$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/security/confirm$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/security/reset$, roles: [ROLE_USER] }
- { path: ^/security/logout$, roles: [ROLE_USER]}
- { path: ^/eventjoin, roles: [ROLE_USER] }
- { path: ^/user/, roles: [ROLE_USER] }
- { path: ^/event/.+, roles: [ROLE_USER] }
- { path: ^/message/.+, roles: [ROLE_USER] }
- { path: ^/, roles: [ROLE_USER, ROLE_ADMIN, IS_AUTHENTICATED_ANONYMOUSLY] }
}
C: \ Bitnami \ wampstack -5.6.20-0 \ apache2 \ HTDOCS \ SYM \ Just2 \ SRC \ MeetingBundle \ Controller \ SecurityController. PHP
<?php
namespace MeetingBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
// use Symfony\Component\HttpFoundation\Response;
use MeetingBundle\Entity\User;
/**
* Class SecurityController
*
* @Route("/security")
* @package MeetingBundle\Controller
*/
class SecurityController extends Controller {
/* EXPLANATIONS about security
* http://www.reecefowell.com/2012/04/30/authorisation-on-roles-in-symfony2/
*/
/**
* @Route("/login", name="sec_login_form")
* @Template("MeetingBundle:Security:login.html.twig")
* @Method("GET|POST")
*/
public function loginAction()
{
$auth_checker = $this->get('security.authorization_checker');
if ($auth_checker->isGranted('IS_AUTHENTICATED_ANONYMOUSLY')
&& !($auth_checker->isGranted('ROLE_USER') || $auth_checker->isGranted('ROLE_ADMIN') )
) {
$authenticationUtils = $this->get('security.authentication_utils');
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render (
'MeetingBundle:Security:login.html.twig' ,
array(
'last_username' => $lastUsername,
'error' => $error,
));
}
else {
return $this->render(
'MeetingBundle:Security:msg.html.twig',
array('msg' => "You are already logged in!",)); //case of bundle
}
}
/**
* @Route("/login_check", name="sec_login_check")
*
*/
public function loginCheckAction()
{
print_r(" there is something wrong with the firewall if you see this :loginCheckAction, route name sec_login_check");
// return new Response();- returns, there is an empty page
}
/**
* @Route("/logout", name="sec_logout")
*/
public function logoutAction()
{
}
}
C: \ Bitnami \ wampstack-5.6.20-0 \ apache2 \ HTDOCS \ SYM \ Just2 \ SRC \ MeetingBundle \ Resources \ Views \ Security \ login.html.twig
{% extends "MeetingBundle::layoutBare.html.twig" %}
{% block stylesheets %} {{ parent() }} {% endblock %}
{% block header %} {{ parent() }} {% endblock %}
{% block msg %} {{ parent() }} {% endblock %}
{% block body %}
<form action="{{ path('sec_login_check') }}" method="get" class="form" id="Security_login">
<hr><span class="desc-large-left" > Username: </span>
<hr><input class="topcoat-text-input" type="text" id="username" name="_username" />
<hr><span class="desc-large-left" > Password: </span>
<hr><input class="topcoat-text-input" type="password" id="password" name="_password"/>
<hr><button class="topcoat-button large" type="submit"> {{ 'sec.login'|trans}} </button>
</form>
{% block javascripts %} {{ parent() }} {% endblock %}
{% endblock %}
Что ошибка у вас есть? – DOZ
Проверьте связь с вашей базой данных. – CStff
Ошибка: 'Контроллер должен вернуть ответ (значение null). Вы забыли добавить оператор возврата в свой контроллер? «Я был занят другими вещами последние две недели. Теперь вернитесь, чтобы войти в систему, удалить tranlator, но логин не работает. – olga