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

biz*_*ger 4 php shopping-cart e-commerce prestashop prestashop-1.5

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

我试图通过在RenderList函数上使用以下代码来添加它.但它没有用.

$this->addRowAction('download');
Run Code Online (Sandbox Code Playgroud)

如果我可以为每一行添加自定义操作以及如何处理它,请告诉我.

moe*_* kh 5

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

          $this->addRowAction('export');
Run Code Online (Sandbox Code Playgroud)

然后为这个动作创建链接,它正在使用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();
}
Run Code Online (Sandbox Code Playgroud)

然后你可以使用initProcess()函数或initcontent()函数获取你的新动作并做一些下载

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