小编Ale*_*kin的帖子

phpunit mock方法使用不同的参数进行多次调用

有没有办法为不同的输入参数定义不同的模拟期望?例如,我有一个名为DB的数据库层类.此类具有名为"Query(string $ query)"的方法,该方法在输入时采用SQL查询字符串.我可以为此类(DB)创建模拟,并为依赖于输入查询字符串的不同Query方法调用设置不同的返回值吗?

php phpunit mocking

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

symfony2会话生存期

我遇到了symfony2会话组件的问题.我通过会话容器将一些数据设置为会话,如下所示:

$sess = $this->get( 'session' );
$sess->set( 'some_key', 'some_value' );
Run Code Online (Sandbox Code Playgroud)

但经过一段时间(大约15-20分钟)后,会议就丢失了.

我可以设置会话生存时间参数吗?对我而言,完美的变体就是如果我可以设定一定的会话时间......有人可以帮忙吗?

session symfony

29
推荐指数
3
解决办法
5万
查看次数

CSS ie7 z-index

我试图生成这样的图形: 在此输入图像描述

但我得到:

在此输入图像描述

CSS:

 #green { height: 500px; width: 500px; background-color: green; position:absolute;z-index:13; }
    #red { height: 300px; width: 300px; background-color: red; position:absolute; z-index:17; }
    #blue { height: 400px; width: 400px; background-color: blue; position:absolute; z-index:15;}
Run Code Online (Sandbox Code Playgroud)

HTML:

<div id="blue"></div>
<div id="green">
    <div id="red"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

主要问题是html代码需要像我上面指定的那样确定.请告诉我实现此功能所需的CSS代码(必须与IE7 +兼容).或者JS可能对此有所帮助?我会很高兴任何建议.

html css z-index internet-explorer-7

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

symfony2 textfield自定义标签

我对symfony2 Field组件有一点但不愉快的问题.例如,我想在twig模板中输出表单字段数组:

{% for field in form %}
    {{ form_label( field ) }}: {{ form_field( field ) }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

这里是文本字段配置:

$field = new TextField( 'FieldName', array(
    'label' => 'MyCustomLabel',
) );
Run Code Online (Sandbox Code Playgroud)

但不幸的是,当引擎呈现此输出时,我将'FieldName'作为标签而不是'MyCustomLabel'.如果我输出不在for的表单字段,我就不会有问题(在这种情况下,我可以在模板中为每个字段添加标签).但是脚本在执行之前不知道表单字段的某些数量和配置.所以,我需要为场渲染实现循环方法.而且我也希望留在树枝上......我很乐意提供一个很好的建议:)

forms rendering symfony twig

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

symfony2 tdd开发

有谁能提供一个使用TDD表示法在Symfony2中进行开发的标准示例?或者分享有关TDD Symfony2开发的有趣材料的链接(官方文档:))?

PS是否有人为MVC模式的控制器部分编写单元测试?

tdd phpunit symfony

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

symfony2 redirectResponse

我想用POST参数创建重定向响应.例如,控制器返回一些重定向响应,该响应在http://example.com上进行重定向

...
return new RedirectResponse('http://example.com');
...
Run Code Online (Sandbox Code Playgroud)

有没有办法重定向到此URL(http://example.com)并使用RedirectResponse类将POST参数发送到此URL?

redirect http symfony

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

imagick :: distortimage

我要设置图像透视图.我有空白多边形的笔记本电脑的形象在此输入图像描述

需要在空白区域上拉出另一张图像.像这样: 在此输入图像描述

所以,我有动态失真的代码:

$controlPoints = array( 0, 0,
                             0, 0,
                             0, $im->getImageHeight(),
                             0, $im->getImageHeight(),
                             $im->getImageWidth(), 0,
                             $im->getImageWidth(), 0,
                             $im->getImageWidth(), $im->getImageHeight(),
                            $im->getImageWidth(), $im->getImageHeight());
     /* Perform the distortion */ 
     $im->distortImage(Imagick::DISTORTION_PERSPECTIVE, $controlPoints, true);
Run Code Online (Sandbox Code Playgroud)

如何设置$ controlPoints数组?我不能只为图像的每个角设置4个坐标?不幸的是,imageick :: distort图像的文档很差.

通过使用另一种失真方法解决问题:

$im->cropImage( 125, 121, $center_x, $center_y ); 
     $controlPoints = array(
                    0,0, 35,20, # top left 
                    190,0, 150,30, # top right
                    0,205, -16,105, # bottom right
                    176,135, 115,105 # bottum left
                    );
     /* Perform the distortion */ 
     $im->distortImage(Imagick::DISTORTION_BILINEAR, $controlPoints, true);
Run Code Online (Sandbox Code Playgroud)

php imagick distortion perspective

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

如何将twig服务添加到我的包中?

我创建了新的bundle(AcmeNotificationBundle),我想像使用这样的服务一样使用它:

$notification = $this->get( 'notification' );
$mess = $notification->getNotification( 'Some notification message' )->createView();
Run Code Online (Sandbox Code Playgroud)

但在我的包中,我需要一个twig服务来呈现通知模板.我知道我在Resources\config\services.yml文件中需要这样的东西:

services:
twig:
    class: Path\To\Twig\Class
Run Code Online (Sandbox Code Playgroud)

但我不知道twig class的正确途径是什么.Аnyone遇到了这个问题?将捆绑服务添加到捆绑包的正确方法是什么?

symfony twig

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