我无法弄清楚,为什么我无法登录。
我收到错误消息“ Controller 必须返回响应(给定为空)。您是否忘记在 Controller 中的某处添加返回语句?”
(如果我取消注释,则从 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
安全:
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 在 Twig 模板中。
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\app\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 %}
最佳答案
我认为问题出在 loginCheckAction 中,您应该返回一些不是打印或测试响应的内容:
public function loginCheckAction(){
throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
}
关于php - Symfony2,无法登录,可能是翻译的原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40715116/
我正在使用i18n从头开始构建一个多语言网络应用程序,虽然我自己可以处理一大堆yml文件,但我说的语言(非常)有限,最终我想寻求外部帮助帮助。我想知道这里是否有人在使用UI插件/gem(与django上的django-rosetta不同)来处理多个翻译器,其中一些翻译器不愿意或无法处理存储库中的100多个文件,处理语言数据。谢谢&问候,安德拉斯(如果您已经在rubyonrails-talk上遇到了这个问题,我们深表歉意) 最佳答案 有一个rails3branchofthetolkgem在github上。您可以通过在Gemfi
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我试图获取一个长度在1到10之间的字符串,并输出将字符串分解为大小为1、2或3的连续子字符串的所有可能方式。例如:输入:123456将整数分割成单个字符,然后继续查找组合。该代码将返回以下所有数组。[1,2,3,4,5,6][12,3,4,5,6][1,23,4,5,6][1,2,34,5,6][1,2,3,45,6][1,2,3,4,56][12,34,5,6][12,3,45,6][12,3,4,56][1,23,45,6][1,2,34,56][1,23,4,56][12,34,56][123,4,5,6][1,234,5,6][1,2,345,6][1,2,3,456][123
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我在pry中定义了一个函数:to_s,但我无法调用它。这个方法去哪里了,怎么调用?pry(main)>defto_spry(main)*'hello'pry(main)*endpry(main)>to_s=>"main"我的ruby版本是2.1.2看了一些答案和搜索后,我认为我得到了正确的答案:这个方法用在什么地方?在irb或pry中定义方法时,会转到Object.instance_methods[1]pry(main)>defto_s[1]pry(main)*'hello'[1]pry(main)*end=>:to_s[2]pry(main)>defhello[2]pry(main)
我使用的是Firefox版本36.0.1和Selenium-Webdrivergem版本2.45.0。我能够创建Firefox实例,但无法使用脚本继续进行进一步的操作无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055)错误。有人能帮帮我吗? 最佳答案 我遇到了同样的问题。降级到firefoxv33后一切正常。您可以找到旧版本here 关于ruby-无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055),我们在StackOverflow上找到一个类
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub