Magento2.3.3 Mass Action on custom table grid 给我异常 #0 (Zend_Db_Statement_Exception): SQLSTATE[42S22]: Column not found

Magento2.3.3 Mass Action on custom table grid give me Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42S22]: Column not found

我有 xml 文件位于 Module/view/adminhtml/ui_component/productdesigner_source_order_listing.xml 这个路径 我添加了 massaction。

 <massaction name="listing_massaction">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/tree-massactions</item>
                </item>
            </argument>
            <!-- Generate button of the PDF -->
            <action name="generate_pdf">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="type" xsi:type="string">generate_pdf</item>
                        <item name="label" xsi:type="string" translate="true">Generate Pdf</item>
                        <item name="url" xsi:type="url" path="productdesigner/order/generatePdf"/>
                    </item>
                </argument>
            </action>
        </massaction>

此外,添加了带有 id 的 primaryFieldName,但是当我执行大规模操作时,它给我一个错误,如下所示,缺少列 id 任何人都可以帮助我,我需要定义该列以获取已选择数据?

下面是我的productdesigner/order/generatePdf这个文件代码。

<?php

namespace Company\Integration\Controller\Adminhtml\Order;

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
use Magento\Ui\Component\MassAction\Filter;

class generatePdf extends Action
{
    protected $orderRepository;
    protected $_objectManager;
    protected $_orderpdf;
    protected $_messageManager;
    protected $orderFactory;
    protected $_productRepository;
    public $filter;

    public function __construct(
        Context $context,
        Filter $filter,
        CollectionFactory $collectionFactory,
        \Magento\Framework\ObjectManagerInterface $objectManager,
        \Biztech\Integration\Model\OrderpdfFactory $orderpdfFactory,
        \Magento\Framework\Message\ManagerInterface $messageManager,
        \Biztech\Integration\Model\Mysql4\SourceDesignOrders\CollectionFactory $orderFactory,
        \Magento\Catalog\Model\ProductRepository $productRepository
    ) {
        parent::__construct($context);
        $this->collectionFactory = $collectionFactory;
        $this->filter            = $filter;
        $this->_objectManager    = $objectManager;
        $this->_orderpdf         = $orderpdfFactory;
        $this->_messageManager   = $messageManager;
        $this->orderFactory      = $orderFactory;

        $this->_productRepository = $productRepository;
    }

    public function execute()
    {
        $collection = $this->filter->getCollection($this->orderFactory->create());
        var_dump($collection->getAllIds()); die; 
        $orderIds   = $collection->getAllIds(); 
        // Get the selected orders
        //$orderIds = implode(',', $orderIds);
    }
}

在您的 Model\ResourceModel\Module\Collection.php 文件中添加以下代码。

protected $_idFieldName = 'id';

然后运行这个命令:php bin/magento c:fphp bin/magento cache:flush

希望这对您有所帮助:)