我想用POST请求上传多个文件(没有Ajax).我可以将Symfony 2的表单集合字段与类型文件一起使用,如下所示:
实体代码:
public $pictures;
public function __construct()
{
$this->pictures = new \Doctrine\Common\Collections\ArrayCollection();
}
Run Code Online (Sandbox Code Playgroud)
表格类代码:
$builder->add('pictures', 'collection', array(
'type' => 'file',
'required' => false,
'attr' => array(
'multiple' => 'multiple'
)
));
Run Code Online (Sandbox Code Playgroud)
Twig中的代码:
{% for picture in form.pictures %}
<td>
{{ form_widget(picture) }}
</td>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
我试过了,但似乎没有用.它没有显示任何错误,但它也没有显示输入文件.有任何想法吗?
这有效
$this->assertEquals(1, $crawler->filter('.elementClass')->count()); // filter by class
Run Code Online (Sandbox Code Playgroud)
但是,这似乎不起作用.
$this->assertEquals(1, $crawler->filter('#elementId')->count()); // filter by id
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
如何在缓存之前调整来自URL的图像的大小,缩放和裁剪.我尝试使用以下代码实现此目的.
[cell.profilePicture setImageWithURL:[NSURL URLWithString:[rowData objectForKey:@"pictureUrl"]] placeholderImage:nil];
cell.profilePicture.image = [self imageByScalingAndCroppingForSize:CGSizeMake(cell.profilePicture.frame.size.width, cell.profilePicture.frame.size.height) image:cell.profilePicture.image];
Run Code Online (Sandbox Code Playgroud)
这产生了一个奇怪的结果.首先,它显示未调整大小/缩放/裁剪的版本.但是,当我向下滚动然后返回时,它会显示调整大小/缩放/裁剪的版本.我知道这段代码首先缓存图像并调整大小/缩放/裁剪它们.但是,我无法想出更好的解决方案.我认为应该有一些能够下载图像的东西,以便独立调整大小/缩放/裁剪和缓存.有任何想法吗?
谢谢.
这是我的配置文件:
// app/config/config.yml
fos_rest:
body_listener:
array_normalizer: fos_rest.normalizer.camel_keys
Run Code Online (Sandbox Code Playgroud)
我使用的是最新版本的FOSRestBundle:
// composer.json
"friendsofsymfony/rest-bundle": "dev-master"
Run Code Online (Sandbox Code Playgroud)
这些是我的帖子参数:
// Post parameters
"first_name": "First name",
"last_name": "Last name",
"phone": "Phone"
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
/**
* @ApiDoc(
* resource=true,
* description="Create a new user"
* )
*
* @View()
*/
public function postAction(Request $request)
{
$user = new User();
$form = $this->createForm(new UserType(), $user);
// Request post parameters are not camel cased
// Parameters expected: firstName, lastName, phone
// Parameters got: first_name, last_name, phone
$form->handleRequest($request);
if ($form->isValid()) {
return …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建自己的身份验证提供程序,如http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html.
但是,它一直在说:
ErrorException:警告:ini_set():会话处于活动状态.您目前无法在/../../vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeFileSessionHandler.php第56行更改会话模块的ini设置