在Prestashop ModuleAdminController中添加自定义行操作


Add Custom Row action in Prestashop ModuleAdminController

我想为moduleadmincontroller助手中的每一行添加一个下载按钮。

我试图通过在RenderList函数上使用以下代码来添加它。但它不起作用。

$this->addRowAction('download');

请让我知道我是否可以为每一行添加自定义操作以及如何处理它。

正如您所知,操作是具有默认值数组('view'、'edit'、'delete'、'duplicate')的默认数组;你可以使用它,但如果你想添加新的操作,你应该使用一些功能。例如,你可以转到你的_prestasthop/controllers/admin/AdminRequestSqlController.php此类添加名为"导出"的新操作

          $this->addRowAction('export');

然后,对于为该操作创建链接,它使用displayExportLink()函数,正如您在下面的代码中看到的那样

         public function displayExportLink($token, $id)
{
    $tpl = $this->createTemplate('list_action_export.tpl');
    $tpl->assign(array(
        'href' => self::$currentIndex.'&token='.$this->token.'&
                     '.$this->identifier.'='.$id.'&export'.$this->table.'=1',
            'action' => $this->l('Export')
    ));
    return $tpl->fetch();
}

然后你可以用initProcess()函数或initcontent()函数获得你的新操作,并做一些类似于下载的事情

public function initProcess()
{
    parent::initProcess();
    if (Tools::getValue('export'.$this->table))
    {
        $this->display = 'export';
        $this->action = 'export';
    }
}