Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在prestashop的.tpl文件中添加php代码_Php_Prestashop - Fatal编程技术网

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

如何在prestashop的.tpl文件中添加php代码,php,prestashop,Php,Prestashop,有人知道如何在prestashop的.tpl文件中添加php代码吗..我尝试了很多,但找不到任何解决方案..我想在我的.tpl文件中添加一个邮件函数 这就是函数 <?php $name=$_REQUEST["name"]; $email=$_REQUEST["email"]; $matter=$_REQUEST["matter"]; $subject=$name."has shared a weblink"; $headers = 'MIME-Ve

有人知道如何在prestashop的
.tpl
文件中添加php代码吗..我尝试了很多,但找不到任何解决方案..我想在我的
.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
中查看
错误日志
,最好在模块控制器中添加
php
函数类等


{php}
贬值是有原因的,因为它允许不良做法。Smarty建议将包含的脚本放入PHP逻辑
(控制器、类、函数)

在.tpl文件中使用{PHP}{/PHP}标记在somme版本的Prestashop中是关闭的

我在使用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_.'SmartyBC.class.php');

global $smarty;
$smarty = new SmartyBC();
$smarty->setCompileDir(_PS_CACHE_DIR_.'smarty/compile');
...
…简而言之,使用SmartyBC.class.php而不是Smarty.class.php


(警告:在模板文件中使用{php}{/php}标记在Prestashop中是不推荐的!)

您可以编辑控制器文件,例如,如果您想在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');
}

为什么要在模板文件中添加函数我有一个页面,我想向我的朋友发送电子邮件。因此,我想在该页面上编写一个邮件函数。将其添加到您的业务逻辑中。我尝试了。但它看起来不太好。我创建了一个
sendmail.php
文件,并以我给出的
sendmail.php
作为操作名称的形式创建了一个
sendmail.php
文件函数成功运行,但重定向到
sendmail.php
文件..看起来不太好..我想继续page@KingshukDeb当前页面控制器中的Deb为该邮件添加一个新方法,您可以在需要时调用该方法,而无需重定向到其他页面..我如何调用该方法..我需要在product
列表中使用该方法page
。因此我认为
FrontController
是控制器..我创建了一个公共函数并在onclick方法中调用它,但失败..尝试创建
FrontController
的对象,但失败..怎么办???@Kingshuk Deb像这样调用它
$send_email=(int)Tools::getValue('send_email');如果($send_email&&Validate::isUnsignedId($send_email))$this->Mail()
其中mail是您的公共函数,并像这样调用它
?id_category=3&controller=category&send_email=1
…它将调用
mail()
方法…首先检查此项…要在浏览器中显示php错误(否以查看错误日志),您可以添加一个带有此代码的对齐:ini_set('display_errors','on');到config/config.inc.php,例如在ligne 36之后(您可以看到ini_set('magic_quotes_runtime',0);)
public function displayContent()
{
 IF  ($_POST['submit_form']==1){
   // here submit action mail() for example
 }
  parent::displayContent();
  self::$smarty->display(_PS_THEME_DIR_.'cms.tpl');
}