小编sma*_*ius的帖子

如何在没有渲染路线的情况下获取当前的绝对URL?

在树枝上我需要获得当前的完整uri(url + uri)而不需要渲染它

path('route_test', {param1:1})
Run Code Online (Sandbox Code Playgroud)

怎么弄?

symfony twig

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

symfony2:如何在翻译中包含换行符/换行符?

我的symfony 2.4环境中存在大量问题,在我的翻译中使用换行符

我试过两个:

#messages.de.yml
foo: |
    Hello i am a line
    Hello i am a new line
Run Code Online (Sandbox Code Playgroud)

#messages.de.yml
foo: >
    Hello i am a line
    Hello i am a new line
Run Code Online (Sandbox Code Playgroud)

枝条

#template.html.twig
{{ 'foo'|trans }}
Run Code Online (Sandbox Code Playgroud)

翻译工作但换行没有.

也许我错了,但我想我完全按照文件说的做了.

yaml internationalization symfony twig

8
推荐指数
2
解决办法
8056
查看次数

Symfony2在自定义存储库类中使用查询

我有一个Repository类,其中包含一个调用自定义Query的方法.当我尝试findAllWithRating()从控制器内部调用时,我得到以下异常:

[2/2] QueryException: [Syntax Error] line 0, col 156: Error: Unexpected 'NULL'
Run Code Online (Sandbox Code Playgroud)

如果我尝试在phpmyadmin中调用查询,则查询效果很好!

任何的想法?

<?php
namespace Anchorbrands\Bundle\MessageBundle\Entity;

use Doctrine\ORM\EntityRepository;

class MessageRepository extends EntityRepository
{

    public function findAllWithRating() {
        return $this->getEntityManager()
            ->createQuery("SELECT id, user_id, title, slug, content, question, image_name, created_at, updated_at,
                    MAX(CASE WHEN rating = '1' THEN totalCount ELSE NULL END) 'Rating 1',
                    MAX(CASE WHEN rating = '2' THEN totalCount ELSE NULL END) 'Rating 2',
                    MAX(CASE WHEN rating = '3' THEN totalCount ELSE NULL END) 'Rating 3'
            FROM
            ( …
Run Code Online (Sandbox Code Playgroud)

sql doctrine dql symfony doctrine-orm

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

在数组集合中按规范查找元素的最佳方法

假设我有两个实体:

  • 实体 A:地点
  • 实体B:图像

一个位置拥有多个图像(一对多)。图像可能具有属性类型。我经常遇到一个用例,我需要按类型过滤图像。目前,我通过生命周期回调来完成此操作,如下例所示:

    /**
     * This functions sets all images when the entity is loaded
     *
     * @ORM\PostLoad
     */
    public function onPostLoadSetImages($eventArgs)
    {
        $this->recommendedForIcons = new ArrayCollection();
        $this->whatYouGetImages    = new ArrayCollection();

        foreach ($this->getImages() as $image) {

            if ('background-image' === $image->getType()->getSlug()) {
                $this->backgroundImage = $image;
            } elseif ('product-icon' === $image->getType()->getSlug()) {
                $this->mainIcon = $image;
            } elseif ('product-image' === $image->getType()->getSlug()) {
                $this->productImage = $image;
            } elseif ('recommended-icon' === $image->getType()->getSlug()) {
                $this->recommendedForIcons->add($image);
            } elseif ('what-you-get-image' === $image->getType()->getSlug()) {
                $this->whatYouGetImages->add($image);
            } elseif …
Run Code Online (Sandbox Code Playgroud)

symfony doctrine-orm

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

AuthenticationSuccessHandlerInterface和正确的重定向策略

我有一个登录success_handler,它将某些用户重定向到一个特殊的表单.无论如何,AuthenticationSuccessHandlerInterface需要返回一个Response并且除了一个案例之外还能正常工作.如果用户首先填写他的凭证错误并再次重定向到登录页面,则处理程序在正确登录后将其重定向到登录页面.

如果我只是使用选项use_referer:true它是正确的.所以我可以把逻辑放到控制器而不是一个事件,但也许你们中的某个人有我的解决方案.

谢谢

火墙

firewalls:
    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
            success_handler: applypie_userbundle.login.handler
            #default_target_path: applypie_user_dashboard
            use_referer: true
        logout:       true
        anonymous:    true
Run Code Online (Sandbox Code Playgroud)

事件

namespace Applypie\Bundle\UserBundle\EventListener;

use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\HttpFoundation\Request;


class NewUserListener implements AuthenticationSuccessHandlerInterface
{
    protected $router;

    public function __construct(RouterInterface $router)
    {
        $this->router = $router;
    }

    public function onAuthenticationSuccess(Request $request, TokenInterface $token)
    {
        $user = $token->getUser();

        if(!$user->getApplicant() && !count($user->getCompanies())) {

            return new RedirectResponse($this->router->generate('applypie_user_applicant_create'));

        }
            return new RedirectResponse($request->headers->get('referer'));
    }
}
Run Code Online (Sandbox Code Playgroud)

服务

applypie_userbundle.login.handler:
    class: Applypie\Bundle\UserBundle\EventListener\NewUserListener
    arguments: …
Run Code Online (Sandbox Code Playgroud)

symfony

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

标签 统计

symfony ×5

doctrine-orm ×2

twig ×2

doctrine ×1

dql ×1

internationalization ×1

sql ×1

yaml ×1