Prestashop HelperList 回调..如何制作带有 url 值的简单按钮?
Prestashop HelperList callback.. how make simple button with a value on url?
我制作了一个模块,我需要在我的助手列表中制作一个自定义按钮来获取一个值并打开一个文件,但是我在 HelperList
上的回调不起作用...
我的代码:
protected function initList()
{
$this->_select = 'a.id_rec_ps_beta AS id_lol';
$this->fields_list = array(
'name' => array(
'title' => $this->getTranslator()->trans('Category name', array(), 'Modules.Recpsbeta.Admin'),
'class' => 'fixed-width-xxl',
'type' => 'text',
'search' => false,
'orderby' => false
),
.....
'id_lol' => array(
'title' => 'LOL',
'align' => 'text-center',
'callback' => 'giveMyCallBack',
'orderby' => false,
'search' => false,
'remove_onclick' => true
)
);
$helper = new HelperList();
$helper->shopLinkType = '';
$helper->simple_header = false;
$helper->identifier = 'id_rec_ps_beta';
//$helper->definition = $helper->identifier;
$helper->actions = array('edit', 'delete');
$helper->show_toolbar = true;
$helper->toolbar_btn['new'] = array(
'href' => AdminController::$currentIndex.'&configure='.$this->name.'&add'.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->getTranslator()->trans('Add new', array(), 'Modules.Recpsbeta.Admin')
);
$helper->toolbar_btn['edit'] = array(
'href' => AdminController::$currentIndex.'&configure='.$this->name.'&setting'.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->getTranslator()->trans('Setting', array(), 'Modules.Recpsbeta.Admin'),
);
$helper->title = $this->displayName;
$helper->table = $this->name;
$helper->orderBy = 'position';
$helper->orderWay = 'ASC';
$helper->position_identifier = 'id_rec_ps_beta';
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
return $helper;
}
调用函数后:
public function giveMyCallBack ($id_rec_ps_beta)
{
return 'lol';
}
但我的列表是这样的:
而在我的页面报错之前:
"警告行 335 文件 C:\wamp64\www\ps2\classes\helper\HelperList.php
[ 2 ] call_user_func_array() 期望参数 1 是一个有效的回调,class 'AdminModulesController' 没有方法 'giveMyCallBack'"
有人帮我吗?好几天没找到解决方法。
谢谢。
PrestaShop:1.7.3.3
阿帕奇:2.4.27 (Win64)
PHP:5.6.31
MySQL: 5.7.19
目前我只找到这个解决方案:
$this->fields_list = array(
'id_rec_ps_beta' => array(
'title' => $this->trans('Title', array(), 'Admin.Global'),
'search' => false,
'align' => 'text-center',
'class' => 'fixed-width-xs',
'prefix' => '<span class="btn-group-action"><span class="btn-group"><a class="btn btn-default" style="padding: 0px 0px;border-color: #efefef;" href="'.AdminController::$currentIndex.'&configure='.$this->name.'&gen'.$this->name.'&btngenrecpsbeta&id_rec_ps_beta=',
'suffix' => '&print=1&token='.Tools::getAdminTokenLite('AdminModules').'"><img src="'.__PS_BASE_URI__.'modules/recpsbeta/views/img/sync.png" style="width: 35px;"></a></span></span>'
),
);
希望对大家有用。
我制作了一个模块,我需要在我的助手列表中制作一个自定义按钮来获取一个值并打开一个文件,但是我在 HelperList
上的回调不起作用...
我的代码:
protected function initList()
{
$this->_select = 'a.id_rec_ps_beta AS id_lol';
$this->fields_list = array(
'name' => array(
'title' => $this->getTranslator()->trans('Category name', array(), 'Modules.Recpsbeta.Admin'),
'class' => 'fixed-width-xxl',
'type' => 'text',
'search' => false,
'orderby' => false
),
.....
'id_lol' => array(
'title' => 'LOL',
'align' => 'text-center',
'callback' => 'giveMyCallBack',
'orderby' => false,
'search' => false,
'remove_onclick' => true
)
);
$helper = new HelperList();
$helper->shopLinkType = '';
$helper->simple_header = false;
$helper->identifier = 'id_rec_ps_beta';
//$helper->definition = $helper->identifier;
$helper->actions = array('edit', 'delete');
$helper->show_toolbar = true;
$helper->toolbar_btn['new'] = array(
'href' => AdminController::$currentIndex.'&configure='.$this->name.'&add'.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->getTranslator()->trans('Add new', array(), 'Modules.Recpsbeta.Admin')
);
$helper->toolbar_btn['edit'] = array(
'href' => AdminController::$currentIndex.'&configure='.$this->name.'&setting'.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->getTranslator()->trans('Setting', array(), 'Modules.Recpsbeta.Admin'),
);
$helper->title = $this->displayName;
$helper->table = $this->name;
$helper->orderBy = 'position';
$helper->orderWay = 'ASC';
$helper->position_identifier = 'id_rec_ps_beta';
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
return $helper;
}
调用函数后:
public function giveMyCallBack ($id_rec_ps_beta)
{
return 'lol';
}
但我的列表是这样的:
而在我的页面报错之前: "警告行 335 文件 C:\wamp64\www\ps2\classes\helper\HelperList.php [ 2 ] call_user_func_array() 期望参数 1 是一个有效的回调,class 'AdminModulesController' 没有方法 'giveMyCallBack'"
有人帮我吗?好几天没找到解决方法。
谢谢。
PrestaShop:1.7.3.3 阿帕奇:2.4.27 (Win64) PHP:5.6.31 MySQL: 5.7.19
目前我只找到这个解决方案:
$this->fields_list = array(
'id_rec_ps_beta' => array(
'title' => $this->trans('Title', array(), 'Admin.Global'),
'search' => false,
'align' => 'text-center',
'class' => 'fixed-width-xs',
'prefix' => '<span class="btn-group-action"><span class="btn-group"><a class="btn btn-default" style="padding: 0px 0px;border-color: #efefef;" href="'.AdminController::$currentIndex.'&configure='.$this->name.'&gen'.$this->name.'&btngenrecpsbeta&id_rec_ps_beta=',
'suffix' => '&print=1&token='.Tools::getAdminTokenLite('AdminModules').'"><img src="'.__PS_BASE_URI__.'modules/recpsbeta/views/img/sync.png" style="width: 35px;"></a></span></span>'
),
);
希望对大家有用。