FOSUser Bundleを使用して登録した後で、デフォルトのプロフィール画像を追加しようとしています。しかし、私は__constructにこの種のファイルを追加する方法を知らないので、イメージマッピングされたエンティティが必要です。ここで__construct()内の画像タイプファイル
は私のUserエンティティである:
<?php
// src/AppBundle/Entity/User.php
namespace AppBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string")
*
* @Assert\NotBlank(message="L'image doit être au format jpg")
* @Assert\File(maxSize = "100k",mimeTypes={ "image/jpg" })
*/
private $image;
public function getImage()
{
return $this->image;
}
public function setImage($image)
{
$this->image = $image;
return $this;
}
public function __construct()
{
parent::__construct();
// your own logic
$this->image = 'http://lorempixel.com/300/300/';
}
}
私は適応しようとした:https://symfony.com/doc/current/controller/upload_file.html
質問は表示されません。あなたが持っている問題を説明してください。デフォルトのイメージはデータベースに残っていないか、または表示されませんか?問題を特定しようとしましたか?出力またはログにエラーメッセージがありますか? – dbrumann