简体   繁体   中英

Custom Sonata admin batch action error

followed by batch action documentation in sonata admin's website, created this custom batch action called AnalayseController.php:

<?php

namespace Admin\Store\Receipt\ReceiptBundle\Controller;

use Sonata\AdminBundle\Controller\CRUDController as BaseController;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

class AnalyseController extends BaseController
{
    /**
     * @param ProxyQueryInterface $selectedModelQuery
     * @param Request             $request
     *
     * @return RedirectResponse
     */

    public function batchActionAnalyse(ProxyQueryInterface $selectedModelQuery, Request $request = null)
    {

        $request = $this->get('request');
        $modelManager = $this->admin->getModelManager();

        $target = $modelManager->find($this->admin->getClass(), $request->get('targetId'));

        if ($target === null){
            $this->addFlash('sonata_flash_info', 'No target!');

            return new RedirectResponse(
                $this->admin->generateUrl('list', $this->admin->getFilterParameters())
            );
        }

        $selectedModels = $selectedModelQuery->execute();
        $this->addFlash('sonata_flash_success', 'Done');
        return new RedirectResponse(
            $this->admin->generateUrl('list', $this->admin->getFilterParameters())
        );
    }
}

but I'm getting this error: Catchable Fatal Error: Argument 1 passed to Admin\\Store\\Receipt\\ReceiptBundle\\Controller\\AnalyseController::batchActionAnalyse() must implement interface Sonata\\AdminBundle\\Datagrid\\ProxyQueryInterface, string given, called in /home/aien/Web/Mr Alef/MRA_Dev/app/cache/dev/appDevDebugProjectContainer.php on line 852 and defined .

looked everywhere, but couldn't find any solution!

Ok, I've fixed the issue just by changing serives.yml calls first argument to setTranslationDomain

admin_store_receipt_receipt.admin.analyse:
        class: Admin\Store\Receipt\ReceiptBundle\Admin\ReceiptAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: admin, label: Receipt }
        arguments:
            - ~
            - Admin\Store\Receipt\ReceiptBundle\Entity\Receipt
            - AdminStoreReceiptReceiptBundle:Analyse
        calls:
            - [ setTranslationDomain , [AdminStoreReceiptReceiptBundle]]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM