小编Ahm*_*ani的帖子

如何自定义FOS UserBundle URL

我已经安装FOSUserBundle,我想自定义URL中/account/login,/account/register,/account/logout而不是/login,/register,/logout

我知道我可以修改捆绑包的路由配置,但它似乎不是正确的方法.

php symfony fosuserbundle

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

twig:无法覆盖包含文件中的块

如何覆盖包含的模板文件中的块?

例:

{# layout.html #}
{% include "menu.html" %}

{# menu.html #}
{% block overrideme %}{% endblock %}

{# index.html #}
{% extends "layout.html" %}
{% block overrideme %}Overriden{% endblock %}
Run Code Online (Sandbox Code Playgroud)

我在某处读到了特质功能的实现?我找不到任何关于它的文档,有谁知道我怎么能做到这一点?

php symfony twig

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

在Symfony 2.1中单元测试自定义验证约束但不访问容器?

我如何单元测试ContainsItalianVatinValidator自定义验证器,但w*不访问容器*和validator服务(从而创建存根对象)?

class ContainsItalianVatinValidator extends ConstraintValidator
{
    /**
     * @param mixed $value
     * @param \Symfony\Component\Validator\Constraint $constraint
     */
    public function validate($value, Constraint $constraint)
    {    
        if (!preg_match('/^[0-9]{11}$/', $value, $matches)) {
            $this->context->addViolation($constraint->message, array(
                '%string%' => $value
            ));
        }

        // Compute and check control code
        // ...
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的测试用例中,我知道我应该访问ConstraintViolationList,但我不知道如何从验证器本身做到这一点:

class ContainsItalianVatinValidatorTest extends \PHPUnit_Framework_TestCase
{
    public function testEmptyItalianVatin()
    {
        $emptyVatin = '';
        $validator  = new ContainsItalianVatinValidator();
        $constraint = new ContainsItalianVatinConstraint();

        // Do the validation
        $validator->validate($emptyVatin, $constraint);

        // …
Run Code Online (Sandbox Code Playgroud)

phpunit symfony symfony-2.1

13
推荐指数
3
解决办法
7386
查看次数

在symfony 2中的控制器内加载文件内容

我有一个名为'style.css'的css文件,我想在控制器中加载它的内容.在阅读官方文档(包括Cookbook)时,我没有找到任何相关的解决方案.

php symfony

13
推荐指数
2
解决办法
3万
查看次数

Sonata Media Bundle:访问媒体网址

我正在使用奏鸣曲媒体包.

我想知道如何在树枝上访问媒体网址.
我只想要网址,我不需要向媒体展示.

有什么建议?

symfony twig sonata-admin

11
推荐指数
3
解决办法
2万
查看次数

Symfony2预定义参数

我在Symfony2配置文件中找到了一些预定义的参数,即.%kernel.root_dir%,%kernel.debug%.

  • 这些地方有完整的清单吗?

configuration symfony

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

限制字符串树枝

如何限制字符串长度?我越来越从我的数据库中的描述值,但我想显示一些特定的字符.

  • 如何在我的树枝模板中执行此操作?
  • 在我的控制器中做它更好吗?

templates symfony twig

11
推荐指数
3
解决办法
2万
查看次数

角度i18n应用的Nginx配置

我使用支持法语和英语的i18n构建了一个angular-5应用程序.然后,我为每种支持的语言部署了一个单独的应用程序版本

 - dist
    |___ en/
    |    |__ index.html
    |___ fr/
         |__ index.html

我还添加了以下nginx配置,以两种语言提供应用程序;

server {
    root /var/www/dist;
    index index.html index.htm;
    server_name host.local;

    location ^/(fr|en)/(.*)$ {
        try_files $2 $2/ /$1/index.html;
    }
}

我想要做的是为两个应用程序提供服务,并允许在英语和法语版本之间切换.

比方说,host.local/en/something 如果我切换到host.local/fr/something我应该得到"某事"页面的法语版本.

使用我共享的nginx配置,每次刷新我的应用程序时刷新页面都会出现404未找到的错误,这也会阻止我独立浏览我的应用程序并在它们之间切换.

我错过了什么?什么是适当的Nginx conf来实现这一目标?

nginx internationalization angular

10
推荐指数
3
解决办法
3370
查看次数

Laravel有许多关系计数在帖子上的喜欢和评论数量

代码:

$posts = Jumpsite::find($jid)
            ->posts()
            ->with('comments')
            ->with('likes')
            ->with('number_of_comments')
            ->with('number_of_likes')
            ->where('reply_to', 0)
            ->orderBy('pid', 'DESC')
            ->paginate(10);
Run Code Online (Sandbox Code Playgroud)

每个帖子都有评论和喜欢.我最初只显示一些注释以避免大负荷.但是我希望显示每篇文章的评论和喜欢的数量.我该怎么做呢?

型号代码:

public function likes()
{
    return $this->hasMany('Like', 'pid', 'pid');
}

public function comments()
{
    return $this->hasMany('Post', 'reply_to', 'pid')->with('likes')->take(4);
}

public function number_of_likes()
{
    return $this->hasMany('Like', 'pid', 'pid')->count();
}
Run Code Online (Sandbox Code Playgroud)

注意:

This is an API. All will be returned as JSON.
Run Code Online (Sandbox Code Playgroud)

更新

回报

Post
    author_id
    message
    Comments(recent 4)
        user_id
        message
        post_date
        Number_of_likes
    Likes
        user_id
    Number_of_total_comments
    Number_of_total_likes
Run Code Online (Sandbox Code Playgroud)

更新

我如何返回数据

$posts  = $posts->toArray();
$posts  = $posts['data'];

return Response::json(array(
   'data' …
Run Code Online (Sandbox Code Playgroud)

php mysql laravel eloquent

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

Symfony2中的jQuery datepicker给出"此值无效".

我在symfony2表单中添加了一个jQuery datepicker.

树枝文件:

$('.date').datepicker({ 
    showOn: 'button', 
    buttonImageOnly: true, 
    changeMonth: true,
    changeYear: true,
    dateFormat: 'yy-MM-dd ',
    yearRange: "-0:+1"  
});
Run Code Online (Sandbox Code Playgroud)

PostType.php

$builder->add('toDate','datetime',array(
                'input' => 'datetime',
                'widget' => 'single_text',
                'format' => 'yy-MM-dd',
                'attr' => array('class' => 'date')
        ));
Run Code Online (Sandbox Code Playgroud)

我尝试了几种日期格式.但是This value is not valid.当我提交时,我总是得到.我试图获取表单错误,但它不提供任何更多信息.

jquery symfony jquery-ui-datepicker

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