John Davidson

php - redirect link between smarty and frontController

0 comments
Message:


I have a tpl-file which contains the display of my prestashop hook and I would like, via a button to call a function of the front controller, only I can't do it probably because of the url, anyone have an idea? My function redirection() can just redirect the link to te log-in page. Thank youuuuu


my tpl files in view/templates/hook


<div class="block-content">
{* variable simple *}
<h2 class="title2">{$title}</h2>
{* recherche la value d'un tableau multidimensionnel en se basant sur sa key*}
<h3>Bonjour {$name.firstname} {$name.lastname}</h3>
{* recherche la key en fonction de la value du tableau *}
{if {$age.Guillaume} > 18}
<p>Client majeur</p>
{else}
<p>Client mineur</p>
{/if}
{* recherche l'index 1 dans le tableau *}
<p>Vous avez le numéro {$number[1]} qui vous est assigné</p>

{* traduction directement dans le back-office *}
<button><a class="controller_link" href="modules/mymodule/controllers/front/display.php?redirection">{l s='Join the Controller' mod='mymodule'}</a></button>
</div>

and my front controller in controller/front/display.php


<?php
/**
* <ModuleClassName> => Mymodule
* <FileName> => Display
* Format expected: <ModuleClassName><FileName>ModuleFrontController
*/
class MymoduleDIsplayModuleFrontController extends ModuleFrontController
{
public function __construct()
{
parent::__construct();

}
public function initContent()
{
parent::initContent();
$this->setTemplate('modules/mymodule/views/templates/hook/displayleftcolumnproduct.tpl');
}
public function redirection()
{
header('Location: https://php74.localhost/prestashop/nous-contacter');
}
}


My Answer:
To redirect to the `redirection()` function in your front controller from the button in your tpl file, you can modify the href attribute of the anchor tag as follows:


{l s='Join the Controller' mod='mymodule'}


This will generate the correct URL to call the `redirection()` function in your front controller when the button is clicked. Make sure to replace `{$link->getModuleLink('mymodule', 'display', ['redirection' => true])}` with the appropriate Smarty variable that generates the correct URL for your Prestashop installation.

Additionally, make sure that the `redirection()` function is accessible from the front controller and that it is properly defined to redirect to the desired page.

Rate this post

5 of 5 based on 8928 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us