4

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

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

$this->addRowAction('download');

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

4

1 回答 1

5

如您所知,操作是具有默认值的默认数组 array('view', 'edit', 'delete', 'duplicate'); 你可以使用它,但如果你想添加新的动作,你应该使用一些功能。例如,你可以去 your_prestashop/controllers/admin/AdminRequestSqlController.php 这个类添加新的动作与'export'名称

          $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';
    }
}
于 2013-12-16T13:09:02.793 回答