繁体   English   中英

如何在prestashop中的.tpl文件中添加php代码

[英]how to add php code in .tpl file in prestashop

有谁知道如何添加PHP代码中.tpl在prestashop..i文件尝试了很多,但找不到任何solutions..I想在我添加邮件功能.tpl文件

这是功能

<?php
    $name=$_REQUEST["name"];
    $email=$_REQUEST["email"];
    $matter=$_REQUEST["matter"];
    $subject=$name."has shared a weblink";
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $contactMsg = '
    <html>
    <head>
    <title>Tell A Friend</title>
    </head>
    <body>
    <table>
    <tr>
    <td>E-mail: '.$email.' </td>
    </tr>
    <tr>
    <td>Comment: '.$matter.' </td>
    </tr>
    </table>
    </body>
    </html>
    ';
    $headers .= "from:abcd" . "\r\n";
    $headers .= "To: Info <info@abcd.in";
    $headers .= "reply-to:".$email."\r\n";
    $headers .= "Cc:".$email."\r\n";
    $headers .= 'Bcc: ' . "\r\n";
    if(mail($email, $subject, $contactMsg, $headers))
    {
    $_REQUEST = array();
    $error.="Mail Sent Successfully"; 
    }
    else
    {
    $error.="Error Mail Sent Fail!"; 
   // 
    }
 ?>

我试着在{php} {/php}块中编写代码。但是无济于事,如何在prestashop查看error log

您可以编辑控制器文件,例如。 如果要在cms页中添加表单,则必须编辑此/controller/CMSController.php

编辑这个

public function displayContent()
{
  parent::displayContent();
  self::$smarty->display(_PS_THEME_DIR_.'cms.tpl');
}

有了这个

public function displayContent()
{
 IF  ($_POST['submit_form']==1){
   // here submit action mail() for example
 }
  parent::displayContent();
  self::$smarty->display(_PS_THEME_DIR_.'cms.tpl');
}

最好在模块控制器中添加php函数类,

{php}之所以贬值,是因为它允许不良做法。 Smarty建议将随附的脚本放入PHP逻辑(controllers,classes,functions)

在Prestashop的某些版本中,.tpl文件中的{php} {/ php}标签的使用已关闭

我在使用Prestashop 1.5.4.1时遇到了相同的问题,要在文件config / smarty.config.inc.php中打开它进行更改:

找到这些行(第27行到第33行)

...
define('_PS_SMARTY_DIR_', _PS_TOOL_DIR_.'smarty/');

require_once(_PS_SMARTY_DIR_.'Smarty.class.php');

global $smarty;
$smarty = new Smarty();
$smarty->setCompileDir(_PS_CACHE_DIR_.'smarty/compile');
...

更改为

...
define('_PS_SMARTY_DIR_', _PS_TOOL_DIR_.'smarty/');

require_once(_PS_SMARTY_DIR_.'SmartyBC.class.php');

global $smarty;
$smarty = new SmartyBC();
$smarty->setCompileDir(_PS_CACHE_DIR_.'smarty/compile');
...

...不久,请使用SmartyBC.class.php而不是Smarty.class.php

(警告:Prestashop中不建议在模板文件中使用{php} {/ php}标签!)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM