小编San*_*nti的帖子

在Symfony 2中访问侦听器中的数据库

我们需要在侦听器中访问数据库信息.我们在service.yml中配置监听器.监听器如下:

namespace company\MyBundle\Listener;

use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class RequestListener
{
    protected $container;

public function __construct(ContainerInterface $container)
{
    $this->container = $container;
}

public function onKernelRequest(GetResponseEvent $event)
{
...
Run Code Online (Sandbox Code Playgroud)

我们如何在onKernelRequest函数中访问doctrine?

我试图从控制器扩展并做:

        $em = $this->getDoctrine()->getEntityManager(); 
Run Code Online (Sandbox Code Playgroud)

它有效,但我认为这是一个不好的做法.

bundle listener symfony doctrine-orm

10
推荐指数
1
解决办法
1万
查看次数

Apache 404错误记录到其他日志文件

我们希望将404未找到的错误分离到不同的日志文件中.现在我们写入此错误的日志文件(apache)位于"access.log"文件中.

我们希望在notfound.log中找到404未找到的错误

我在apache2.conf中做了一个测试写入:

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" notfound
Run Code Online (Sandbox Code Playgroud)

并在VirtualHost的apache站点 - 可用:

CustomLog ${APACHE_LOG_DIR}/not-found.log notfound expr=.*404.*
Run Code Online (Sandbox Code Playgroud)

但是我得到了"条件条款错误"

我也尝试在VirtualHost中设置一个env变量:

SetEnvIf expr .*404.* httpcode
Run Code Online (Sandbox Code Playgroud)

并在CustomLog expr中调用它但没有工作.有人可以帮助我们吗?

谢谢.

apache logging

9
推荐指数
1
解决办法
3710
查看次数

标签 统计

apache ×1

bundle ×1

doctrine-orm ×1

listener ×1

logging ×1

symfony ×1