我想在Symfony 4.3.2项目中的控制器构造中获取用户对象。根据上的文档,我只需要调用$this->getUser()。是的,这在行动方法中起作用。
但是:尝试让用户进入构造函数是行不通的,因为容器在这里不会被初始化,而且getUser方法会抛出一个异常“调用成员函数有() on null":容器此时为null。
这样做是可行的:
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class TestControlle
我正在Symfony2中开发一个websocket应用程序。我使用了一个基于棘轮( symfony2,)的包调用ClankBundle ()。
我已经成功地在symfony2中配置了我的服务,并且服务器正在运行…以这里为例,当我调用JS network.onSubscribe时,所有已经订阅的人都会收到相关信息。
class ChatTopic implements TopicHandlerInterface
{
/**
* Announce to this topic that someone else has joined the chat room
* Also, set their
我被困在这里了。我试图在Ajax Action中包含一个EventDispatcher,但是它悄悄地失败了。我是symfony的新手,目前正在对基于symfony 1.1.6的"VImp“内容管理系统()进行定制。
在/apps/xx/modules/xx/actions/base/BaseXxActions.php中是这样的:
public function executeAjax {
switch($this->getVar('action')) {
case 'something':
在Symfony2.7中,我能够在创建表单时直接从控制器传递参数到form构造函数,但是在Symfony3中,我不能这样做!
以前在Symfony2.7中
$postedBy = $this->getUser()->getFullname();
$form = $this->createForm(new NewsType($postedBy));
后 in Symfony3
$form = $this->createForm(NewsType::class); // no idea how to pass parameter?
更新:我还想从以下位置访问:
$build
我在试着测试我的服务。此服务调用其他服务,如security.context。当调用AlbumHandler时,模拟在security.context步骤中失败。
错误:
PHP Fatal error: Call to a member function getToken() on a non-object
代码:
public function setUp()
{
$this->container = $this->getMock('\Symfony\Component\DependencyInjection\ContainerI
所以我正在构建一个Symfony网络应用程序。
我有一个简单控制器(DefaultController.php),如下所示:
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class DefaultController exte
在控制器中检查security.context服务的getUser()调用的对象实际上是我的自定义user类的对象,这是不是一个好主意?
public function editAction()
{
$user = $this->container->get('security.context')->getToken()->getUser();
if (!is_object($user) || !$user instanceof \Acme\UserBundle\User) {
throw new AccessDenied
目标是将当前登录的用户转储到web profiler。
我有一个注入了Container的侦听器类:
namespace Bookboon\Premium\AppBundle\EventListener;
use Classes\geoPlugin;
use Bookboon\Premium\AppBundle\Controller;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\DependencyInjection\Container;
class CountryL
你们symfony2专家中有谁能给我一些启发,告诉我如何从symfony2服务中编写一条flash消息?
Fatal error: Call to undefined method appDevDebugProjectContainer::getRequest() in /var/www/cloudsign_beta/src/BizTV/CommonBundle/Helper/globalHelper.php on line 135
所以很明显我不能访问请求...如果我也必须从控制器传递它,我很快就会失去一个服务的点,它不能自己做任何事情=)
<?php
namespace BizTV
我试图访问服务中的用户,以便跟踪最新的活动。然而,它会引发一个错误:
错误:调用非对象上的成员函数getUser()
但是,如果我var_dump和die() 用户对象,我可以看到信息。
有什么想法吗?
ActivityListener
<?php
namespace AppBundle\EventListener;
use AppBundle\Entity\User;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\F
当我这样做时,如何获得用户类而不是Userinterface:
$this->security->getUser() (安全是Symfony\Component\Security\Core\Security;)
通过示例(它只是一个示例:),我具有以下自定义函数:
public function getUser(User $user){
}
当我这么做的时候
public function __construct(
Security $security,
) {
$this->security = $security;
}
g
当我调用实体提议时,我遇到了一个问题,我想调用方法getApplication(),但是我发现这个错误无法猜测如何从参数“要约”的请求信息中获取一个Doctrine实例。有人知道怎么叫实体吗?谢谢
<?php
namespace App\Controller;
use App\Entity\Application;
use App\Entity\Offer;
use App\Repository\ApplicationRepository;
use App\Repository\BrandRepository;
use App\Repository\OfferRepository;
u
在Symfony2中,我使用自定义约束来验证表单上的一些数据,但是我想知道是否可以从表单中引入一个值来验证另一个值?
这是我的限制..。
<?php
// src\BizTV\ContainerManagementBundle\Validator\Constraints\ContainerExists.php
namespace BizTV\ContainerManagementBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class C
当我在CentOS6.4/ PHP 5.5.36服务器上运行‘composer.phar update’时,我收到了大量的消息,开头是:
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of
packages.
Problem 1
- Conclusion: don't install symfony/s
我正在使用DemoSite-broadleaf-5.2.4-GA和以下教程
但我得到了
org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring4.processor.SpringInputGeneralFieldTagProcessor' (template: "authentication/registerForm" - line 71, col 24)
at org.thymelea