Prestashop 如何在PS 1.6中使用ModuleFrontController显示多个视图
对于我的模块前端控制器,我需要初始化它以显示客户必须填写的表单(formulaire.tpl)。然后,控制器使用我的模型(Formulaire.php)中定义的方法处理表单中发布的数据,然后我想让它显示另一个视图(repaitulatif.tpl),该视图显示发送数据的提醒,例如添加到购物车按钮或再次填写表单的可能性。 因为我想用MVC的方式实现它,所以我不想创建一个新的php页面来重定向我的客户,但我想在处理数据之后以某种方式显示第二个模板。控制器有什么方法可以这样做吗?在下面,你可以找到我的代码,它不工作,它显示了我的第一个模板和我的第二个模板Prestashop 如何在PS 1.6中使用ModuleFrontController显示多个视图,prestashop,prestashop-1.6,Prestashop,Prestashop 1.6,对于我的模块前端控制器,我需要初始化它以显示客户必须填写的表单(formulaire.tpl)。然后,控制器使用我的模型(Formulaire.php)中定义的方法处理表单中发布的数据,然后我想让它显示另一个视图(repaitulatif.tpl),该视图显示发送数据的提醒,例如添加到购物车按钮或再次填写表单的可能性。 因为我想用MVC的方式实现它,所以我不想创建一个新的php页面来重定向我的客户,但我想在处理数据之后以某种方式显示第二个模板。控制器有什么方法可以这样做吗?在下面,你可以找到我的
class FormulaireModuleDefaultModuleFrontController extends ModuleFrontController
{
public $ssl = true;
private $done_traitement = false;
public function postProcess()
{
//On vérifie le bouton submit du formulaire
if(Tools::isSubmit('bouton'))
{
// On va commencer en premier par récupérer l'id customer avec la variable cookie
// et vérifier que la personnes est bien loggée
global $cookie;
if(!isset($cookie->id_customer))
{
$message='Aucun client loggé';
}
else
{
$errors=array();
$id_cart=$this->context->cart->id;
$customer=$cookie->id_customer;
//On récupère les valeurs du formulaire
$prix=Tools::getValue('resultat');
$titre='porte_test';
$desc='Largeur de passage de '.Tools::getValue('largeur_passage').' mm, hauteur de passage de '.Tools::getValue('hauteur_passage')
.' mm, hauteur de linteau de '.Tools::getValue('hauteur_linteau').' mm, ecoinçon gauche de '.Tools::getValue('ecoincon_gauche')
.' mm, ecoincon_droit de '.Tools::getValue('ecoincon_droit'). ' mm, motif en '.Tools::getValue('motif_porte').' et de couleur '
.Tools::getValue('couleur_porte');
//On va vérifier les champs obligatoires
//Les champs sont remplis, on va faire le traitement des données.
$idprod=Formulaire::creerProduct($titre,0,13,$prix,$desc, 'mod_100',$customer);
Formulaire::addProduitauPanier($idprod);
$this->done_traitement=true;
}
//On envoie le message si il existe:
if(isset($message))self::$smarty->assign('message',$message);
if(isset($errors))self::$smarty->assign('erreurs',$errors);
}
}
public function initContent()
{
parent::initContent();
if($this->done_traitement)
$this->display(__FILE__,'recapitulatif.tpl');
}
public function init(){
$this->display_column_left = false;
$this->display_column_right = false;
$this->page_name = 'Configurateur';
parent::init();
$this->setTemplate('formulaire.tpl');
}
}
提前感谢您的帮助
编辑:
好的,很抱歉问你这个问题。发帖后我花了2分钟才弄明白。我只需要改变一下:
$this->display(__FILE__,'recapitulatif.tpl');
作者:
现在它开始工作了。很抱歉给您带来不便
$this->setTemplate('recapitulatif.tpl');