我创建了一个钩子,允许用户发送csv文件。我想获取用户通过表单(出现在视图/模板/钩子中)发送的数据(文件),在控制器/前台/files.php中获取数据,并将其插入到我的数据库中,有人知道吗?
我在mymodule.php的钩子
public function hookDisplayLeftColumnProduct($params)
{
$this->context->smarty->assign([
'files' => Tools::getValue('files')
]);
return $this->display(__FILE__, 'mymodule.tpl');
}视图/模板/钩子/mymodule.tpl
<div id="mymodule_block_home">
<form method="POST">
<label for="files">Envoyer un fichier CSV</label>
<input type="file" name="files" id="files">
<button>Envoyer</button>
</form>
</div>我想我前面的控制器不太好
class MyModuleFilesFrontController extends ModuleFrontController
{
public function initContent()
{
parent::initContent();
$files = Tools::getValue('files');
$this->setTemplate('module:mymodule/views/templates/front/files.tpl');
}
}谢谢你的帮助
发布于 2022-07-20 21:48:35
这不是PrestaShop特有的问题。您可能需要阅读有关在PHP中上载文件的相关内容:https://www.tutorialspoint.com/php/php_file_uploading.htm
以下几点提示:
还有一件事。我看到你把你的模块挂到产品页面上。您可以使用直接在钩子中上传文件的逻辑。你不需要额外的控制器。
你可以这样做:
public function hookDisplayLeftColumnProduct($params)
{
if (Tools::isSubmit('yourSubmitButtonName') {
// here's the logic of uploading the file
}
// the rest of the code
}https://stackoverflow.com/questions/72941248
复制相似问题