php - 仅在生产环境中出现的 Vichuploader 问题
问题描述
我已经在我的网站上实现了 VichUploaderBundle,并且在我的本地环境中一切正常,但是在服务器上上传更新后,服务器端的 prod 环境正在返回:
HTTP 错误 500
服务器端的开发环境返回以下内容:
AppKernel.php 第 33 行中的 ClassNotFoundException:尝试从命名空间“Vich\UploaderBundle”加载类“VichUploaderBundle”。您是否忘记了另一个名称空间的“使用”语句?
这令人困惑,因为我的实体中确实有正确的“使用”语句。这是我的实体代码:
<?php
namespace UserBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* User
*
* @Vich\Uploadable
* @ORM\Table(name="fos_user")
* @ORM\Entity(repositoryClass="UserBundle\Entity\UserRepository")
* @ORM\HasLifecycleCallbacks()
*/
class User extends BaseUser
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=255)
*
* @Assert\NotBlank(message="Please enter your lastname.", groups={"Registration", "Profile"})
* @Assert\Length(
* min=3,
* max=255,
* minMessage="The lastname is too short.",
* maxMessage="The lastname is too long.",
* groups={"Registration", "Profile"}
* )
*/
protected $lastName;
/**
* @ORM\Column(type="string", length=255)
*
* @Assert\NotBlank(message="Please enter your firstname.", groups={"Registration", "Profile"})
* @Assert\Length(
* min=3,
* max=255,
* minMessage="The firstname is too short.",
* maxMessage="The firstname is too long.",
* groups={"Registration", "Profile"}
* )
*/
protected $firstName;
/**
* @ORM\Column(type="string", length=255)
*
* @Assert\NotBlank(message="Please enter your phone.", groups={"Registration", "Profile"})
* @Assert\Length(
* min=8,
* max=255,
* minMessage="The phone value is too short.",
* maxMessage="The phone value is too long.",
* groups={"Registration", "Profile"}
* )
*/
protected $phone;
/**
* @Vich\UploadableField(mapping="users_images", fileNameProperty="userImageName")
* @var File
*/
private $userImageFile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @var string
*/
private $userImageName;
/**
*
* @ORM\OneToOne(targetEntity="MainBundle\Entity\Image", cascade={"persist", "remove"})
*/
private $image;
/**
* @var \DateTime
*
* @ORM\Column(name="date", type="datetime")
*/
protected $date;
/**
* @ORM\Column(name="code", type="integer", nullable=false, unique=true)
*/
protected $code;
/**
* @ORM\Column(name="amount", type="float", nullable=true)
*/
protected $amount;
/**
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
*/
protected $updatedAt;
public function __construct()
{
parent::__construct();
$this->date = new \Datetime();
$this->types = new ArrayCollection();
$random = intval( "0" . rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
$this->code = $random;
}
/*
* @ORM\PreUpdate
*/
public function updateDate()
{
$this->setUpdatedAt(new \Datetime());
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set phone
*
* @param string $phone
* @return User
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set details
*
* @param string $details
* @return User
*/
public function setDetails($details)
{
$this->details = $details;
return $this;
}
/**
* Get details
*
* @return string
*/
public function getDetails()
{
return $this->details;
}
public function setEmail($email)
{
$email = is_null($email) ? '' : $email;
parent::setEmail($email);
$this->setUsername($email);
return $this;
}
public function setEmailCanonical($emailCanonical)
{
$this->emailCanonical = $emailCanonical;
$this->usernameCanonical = $emailCanonical;
}
/**
* Get types
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getType()
{
return $this->type;
}
/**
* Set date
*
* @param \DateTime $date
* @return User
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* @return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Set updatedAt
*
* @param \DateTime $updatedAt
* @return User
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
*
*
* @param string $type
* @return User
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Set image
*
* @param \MainBundle\Entity\Image $image
* @return User
*/
public function setImage(\MainBundle\Entity\Image $image = null)
{
$this->image = $image;
return $this;
}
/**
* Get image
*
* @return \MainBundle\Entity\Image
*/
public function getImage()
{
return $this->image;
}
/**
* Set lastName
*
* @param string $lastName
*
* @return User
*/
public function setLastName($lastName)
{
$this->lastName = $lastName;
return $this;
}
/**
* Get lastName
*
* @return string
*/
public function getLastName()
{
return $this->lastName;
}
/**
* Set firstName
*
* @param string $firstName
*
* @return User
*/
public function setFirstName($firstName)
{
$this->firstName = $firstName;
return $this;
}
/**
* Get firstName
*
* @return string
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* Set code
*
* @param integer $code
*
* @return User
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
/**
* Get code
*
* @return integer
*/
public function getCode()
{
return $this->code;
}
/**
* Set amount
*
* @param float $amount
*
* @return User
*/
public function setAmount($amount)
{
$this->amount = $amount;
return $this;
}
/**
* Get amount
*
* @return float
*/
public function getAmount()
{
return $this->amount;
}
/**
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile | null $userImageFile
* @return User
*/
public function setUserImageFile(File $userImageFile = null)
{
$this->userImageFile = $userImageFile;
// VERY IMPORTANT:
// It is required that at least one field changes if you are using Doctrine,
// otherwise the event listeners won't be called and the file is lost
if ($userImageFile) {
// if 'updatedAt' is not defined in your entity, use another property
$this->updatedAt = new \DateTimeImmutable();
}
return $this;
}
/**
* @return File|null
*/
public function getUserImageFile()
{
return $this->userImageFile;
}
/**
* @param string $productName
* @return User
*/
public function setUserImageName($userImageName)
{
$this->userImageName = $userImageName;
return $this;
}
/**
* @return string|null
*/
public function getUserImageName()
{
return $this->userImageName;
}
}
AppKernel.php 代码:
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function __construct($environment, $debug)
{
date_default_timezone_set('Europe/London');
parent::__construct($environment, $debug);
}
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
new MainBundle\MainBundle(),
//new Gregwar\ImageBundle\GregwarImageBundle(),
//new Gregwar\CaptchaBundle\GregwarCaptchaBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new \FOS\ElasticaBundle\FOSElasticaBundle(),
new FOS\UserBundle\FOSUserBundle(),
new UserBundle\UserBundle(),
new Vich\UploaderBundle\VichUploaderBundle(),
//new EasyCorp\Bundle\EasyAdminBundle\EasyAdminBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new CoreSphere\ConsoleBundle\CoreSphereConsoleBundle();
//$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
}
return $bundles;
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
}
}
config.yml 代码:
service:
mailer: fos_user.mailer.twig_swift
vich_uploader:
db_driver: orm
mappings:
users_images:
uri_prefix: '%app.path.users_images%'
upload_destination: '%kernel.root_dir%/../web%app.path.users_images%'
namer: vich_uploader.namer_origname
请注意,我清除了缓存。请问有什么建议吗?
解决方案
推荐阅读
- c# - 如何检查 InputField.Text 是否包含两个随机生成的字母?
- android - Android Grid View:将图像堆叠在另一个之上
- java - 简单的双向 @OneToOne 存储 null
- c# - 获取媒体会话的程序句柄和窗口句柄
- python - 如何实现深度卷积神经网络的反向传播?
- python - 如何在 Python 中使用 BAC0 readRange
- python-3.x - 如何从 RSA 公钥计算指纹?
- python - 如何创建多个包含我所有地块的地块
- reactjs - 如何将对象传递到 ant.design 表单中?
- python - 当随机数生成器在列表中移动时,如何改变它的概率?