Php 在Sylius沙盒中上载产品映像失败

Php 在Sylius沙盒中上载产品映像失败,php,symfony,file-upload,symfony-2.1,sylius,Php,Symfony,File Upload,Symfony 2.1,Sylius,我不知道这个问题是否有效,但我是专门为Symfony问这个问题的 在Sylius沙箱中: 上传产品图片似乎不起作用。在演示站点和本地安装上进行了尝试 将图像上载到产品时,不会发生任何事情。将显示默认占位符,上载目录中不显示任何内容 上载目录也未创建。手动创建它似乎没有效果 我在symfony2.1新安装中使用了代码。 我正在使用应用程序和Sylius sandbox使用bin 任何创建或使用Sylius sandbox的人都可以帮助我 product.php 我也使用sylius sandbox

我不知道这个问题是否有效,但我是专门为Symfony问这个问题的

在Sylius沙箱中: 上传产品图片似乎不起作用。在演示站点和本地安装上进行了尝试

将图像上载到产品时,不会发生任何事情。将显示默认占位符,上载目录中不显示任何内容

上载目录也未创建。手动创建它似乎没有效果

我在symfony2.1新安装中使用了代码。 我正在使用应用程序和Sylius sandbox使用bin

任何创建或使用Sylius sandbox的人都可以帮助我

product.php
我也使用sylius sandbox应用程序作为指南,如果不作为指南使用,它可能会导致更多的混乱,请尝试编写自己的代码,并使用sandbox作为参考

2分

  • 我认为Sylius Sandbox已被弃用(改用)
  • 要实现映像管理,可能有两个选项:1-使用sylius的内置映像管理,它实现每个变量的映像。2-构建自己的实现,类似于产品实体代码中的实现
  • 在我的实现中,我认为使用产品实体与图像实体的一对一关系更简单,这显然取决于您的需求。我用于图像实体

    <?php
    
    namespace Sylius\Sandbox\Bundle\AssortmentBundle\Entity;
    
    use Sylius\Bundle\AssortmentBundle\Entity\CustomizableProduct as BaseProduct;
    use Sylius\Bundle\CategorizerBundle\Model\CategoryInterface;
    use Sylius\Bundle\InventoryBundle\Model\StockableInterface;
    use Symfony\Component\Validator\Constraints as Assert;
    
    class Product extends BaseProduct implements StockableInterface
    {
    const VARIANT_PICKING_CHOICE = 0;
    const VARIANT_PICKING_MATCH  = 1;
    
    /**
     * Product category.
     *
     * @Assert\NotBlank
     *
     * @var CategoryInterface
     */
    protected $category;
    
    /**
     * Variant picking mode.
     * Whether to display a choice form with all variants or match variant for
     * given options.
     *
     * @var integer
     */
    protected $variantPickingMode;
    
    /**
     * Image path.
     *
     * @var string
     */
    protected $imagePath;
    
    /**
     * Image upload.
     *
     * @Assert\File(maxSize="512k")
     * @Assert\Image
     */
    public $image;
    
    /**
     * Set default variant picking mode.
     */
    public function __construct()
    {
        parent::__construct();
    
        $this->variantPickingMode = self::VARIANT_PICKING_CHOICE;
    }
    
    /**
     * Get category.
     *
     * @return CategoryInterface
     */
    public function getCategory()
    {
        return $this->category;
    }
    
    /**
     * Set category.
     *
     * @param CategoryInterface $category
     */
    public function setCategory(CategoryInterface $category)
    {
        $this->category = $category;
    }
    
    public function getVariantPickingMode()
    {
        return $this->variantPickingMode;
    }
    
    public function setVariantPickingMode($variantPickingMode)
    {
        if (!in_array($variantPickingMode, array(self::VARIANT_PICKING_CHOICE, self::VARIANT_PICKING_MATCH))) {
            throw new \InvalidArgumentException('Wrong variant picking mode supplied');
        }
    
        $this->variantPickingMode = $variantPickingMode;
    }
    
    public function isVariantPickingModeChoice()
    {
        return self::VARIANT_PICKING_CHOICE === $this->variantPickingMode;
    }
    
    /**
     * This is a proxy method to access master variant price.
     * Because if there are no options/variants defined, the master variant is
     * the project.
     *
     * @return float
     */
    public function getPrice()
    {
        return $this->masterVariant->getPrice();
    }
    
    /**
     * Implementation of stockable interface.
     * Proxy to use master variant for managing inventory status.
     *
     * {@inheritdoc}
     */
    public function getStockableId()
    {
        return $this->masterVariant->getStockableId();
    }
    
    /**
     * {@inheritdoc}
     */
    public function isInStock()
    {
        return $this->masterVariant->inStock();
    }
    
    /**
     * {@inheritdoc}
     */
    public function getOnHand()
    {
        return $this->masterVariant->getOnHand();
    }
    
    /**
     * {@inheritdoc}
     */
    public function setOnHand($onHand)
    {
        $this->masterVariant->setOnHand($onHand);
    }
    
    public function getImagePath()
    {
        return $this->imagePath;
    }
    
    public function setImagePath($imagePath)
    {
        $this->imagePath = $imagePath;
    }
    
    public function getAbsoluteImagePath()
    {
        return null === $this->getImagePath() ? null : $this->getImageUploadRootDir().'/'.$this->getImagePath();
    }
    
    public function getImageWebPath()
    {
        return null === $this->getImagePath() ? null : $this->getImageUploadDir().'/'.$this->getImagePath();
    }
    
    public function getImageUploadDir()
    {
        return 'uploads/images';
    }
    
    public function hasImage()
    {
        return null !== $this->getImagePath();
    }
    
    public function saveImage()
    {
        if (null === $this->image) {
    
            return;
        }
    
        $this->setImagePath(uniqid().'.'.$this->image->guessExtension());
        $this->image->move($this->getImageUploadRootDir(), $this->getImagePath());
    }
    
    public function deleteImage()
    {
        if ($file = $this->getAbsoluteImagePath()) {
            unlink($file);
        }
    }
    
    protected function getImageUploadRootDir()
    {
        return __DIR__.'/../../../../web/'.$this->getImageUploadDir();
    }
    
    static public function getVariantPickingModeChoices()
    {
        return array(
            self::VARIANT_PICKING_CHOICE => 'Display list of variants',
            self::VARIANT_PICKING_MATCH  => 'Display options'
        );
    }
    
    /**
     * Get comment thread ID.
     *
     * @return string
     */
    public function getCommentThreadId()
    {
        return 'assortment_product_'.$this->getId();
    }
    }