【发布时间】:2019-03-29 22:05:26
【问题描述】:
我创建了自己的模块 cus_avatar,用于上传客户头像。我制作了一个 tpl 文件“uploader.tpl”,其中包含我需要提交的表单,并挂在客户的个人资料页面中。 如何发布此表单?
这是我的代码:
root/modules/cus_avatar/cus_avatar.php:
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class Cus_Avatar extends Module
{
public function __construct()
{
// the module's details and construct codes here
}
public function install()
{
return parent::install()
&& $this->registerHook('header')
&& $this->registerHook('displayEpAvatar')
&& $this->registerHook('displayEpAvatarSidebar')
&& $this->installDb();
}
public function uninstall()
{
return parent::uninstall() && $this->uninstallDb();
}
protected function installDb(){
$alterDb = "CREATE TABLE mydb."._DB_PREFIX_."avatar (
avatar_id INT NOT NULL AUTO_INCREMENT,
id_customer INT NULL,
avatar_path VARCHAR(255) NULL,
PRIMARY KEY (avatar_id)
) ENGINE = MyISAM";
return Db::getInstance()->execute($alterDb);
}
protected function uninstallDb(){
$revertDb = "DROP TABLE "._DB_PREFIX_."avatar";
return Db::getInstance()->execute($revertDb);
}
public function hookHeader($params)
{
$this->context->controller->addCss($this->_path.'assets/css/style.css', 'all');
$this->context->controller->addJS($this->_path.'assets/js/script.js');
}
public function hookDisplayEpAvatar($params)
{
if(isset($_POST['submit_avatar']))
{
// THIS CODE DOESNT SEEM TO WORK
var_dump("HELLO WORLD!");
die();
}
return $this->display(__FILE__, 'views/templates/hook/uploader.tpl');
}
public function hookDisplayEpAvatarSideBar($params)
{
}
}
root/modules/cus_avatar/views/templates/hook/uploader.tpl:
<form name="form_avatar" method="post">
<div class="row">
<div class="col-xs-12 plr30">
<label class="mt20">PROFILE AVATAR</label>
</div>
<div class="col-xs-12 col-md-4 col-lg-3 plr30">
<div class="avatar-container">
<label class="avatar">
<input type="file" accept="image/*">
</label>
</div>
<button type="submit" name="submit-btn">SUBMIT</button>
</div>
<div class="col-xs-12 col-md-8 col-lg-9">
<small class="text-warning">Avatar is updated seperately from the rest of the form.</small>
</div>
</div>
</form>
//忽略这些文本,这些只是为了使描述足够长以便提交。这只敏捷的棕色狐狸跳过了河岸附近的懒狗。
【问题讨论】:
-
你在前端看到你的表单了吗?
-
是的,uploader.tpl 挂在我位于客户资料页面 (site/index?controller=identity) 的自定义挂钩中。
标签: php prestashop prestashop-1.7