0

我有一个用于投资组合管理的商业实体,我使用 vichImage,但我不明白为什么我不能修改或删除图像。如果不修改另一个表单域,我无法更改照片。

<?php

namespace App\Controller\Admin;

use App\Entity\Commercial;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ImageField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Vich\UploaderBundle\Form\Type\VichImageType;

class CommercialCrudController extends AbstractCrudController
{
    public static function getEntityFqcn(): string
    {
        return Commercial::class;
    }

    public function configureCrud(Crud $crud): Crud
    {
        return $crud
            ->setPageTitle(Crud::PAGE_INDEX, 'Commercial Gallery')
            ->setPageTitle(Crud::PAGE_NEW, 'Add Photos')
            ->setPageTitle(Crud::PAGE_EDIT, 'Edit Photo')
            ->setDefaultSort(['created_at' => 'DESC']);
           
            
    }

    public function configureFields(string $pageName): iterable
    {
        // Photos configuration
        $imageFile = TextareaField::new('imageFile', 'Photo')->setFormType(VichImageType::class);
        $image = ImageField::new('commercialPhoto', 'Photo')->setBasePath('images/commercial');


        $fields = [

            IdField::new('id')->onlyOnDetail(),
            TextField::new('name', 'Services name'),
            AssociationField::new('users', 'Published by')->hideOnForm(),
            DateTimeField::new('created_at', 'Date')->hideOnForm(),

        ];

        // CRUD ACTIONS
        if ($pageName == Crud::PAGE_INDEX || $pageName == Crud::PAGE_DETAIL) {
            $fields[] = $image; // afficher l'image dans la page Index et Detail
        } else {
            $fields[] = $imageFile; // afficher l'image dans la page Edit
        }
        return $fields;
    }


    public function configureActions(Actions $actions): Actions
    {
        return $actions // Add boutton show 
            ->add(Crud::PAGE_INDEX, Action::DETAIL);
            
    }

    //create a filter 
    public function configureFilters(Filters $filters): Filters
    {
        return $filters
            ->add('name')
            ->add('users')
            ->add('created_at');
    }
}

在添加这一行之前就足够了,但现在文件已经改变 在此处输入图像描述 是这样的:

namespace EasyCorp\Bundle\EasyAdminBundle\Event;

/**
 * @author Javier Eguiluz <javier.eguiluz@gmail.com>
 */
final class BeforeEntityDeletedEvent extends AbstractLifecycleEvent
{
    use StoppableEventTrait;
    
    
}

当我尝试删除时, 在此处输入图像描述

请问我该怎么办?,我是初学者,提前感谢您的帮助。

4

1 回答 1

0

这只是一个拼写问题,我输入了更新而不是更新。并删除只是添加?在 setCommercial photo 属性中的字符串之前

在此处输入图像描述

于 2022-02-07T04:14:17.123 回答