Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.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
Php 对非对象调用成员函数createTemplate()_Php_Smarty - Fatal编程技术网

Php 对非对象调用成员函数createTemplate()

Php 对非对象调用成员函数createTemplate(),php,smarty,Php,Smarty,我正在迁移一个基于Smarty的网站,我试图满足所有的前提条件,这样就不会有任何问题,但是(“我可能会加上”)我遇到了这个问题,在安装了所有必要的软件包后,网站无法运行(我在浏览器中遇到HTTP 500错误),我在错误日志中发现了这个错误: PHP致命错误:在第47行的/var/www/vhosts/placeholder.com/httpdocs/includes/sysplugins/smarty_internal_templatebase.PHP中对非对象调用成员函数createTempl

我正在迁移一个基于Smarty的网站,我试图满足所有的前提条件,这样就不会有任何问题,但是(“我可能会加上”)我遇到了这个问题,在安装了所有必要的软件包后,网站无法运行(我在浏览器中遇到HTTP 500错误),我在错误日志中发现了这个错误:

PHP致命错误:在第47行的/var/www/vhosts/placeholder.com/httpdocs/includes/sysplugins/smarty_internal_templatebase.PHP中对非对象调用成员函数createTemplate()

这实际上出现在index.php文件中,我在这里有这段代码

$smarty = new SmartyEC($page->template);
$smarty->display('index.tpl');
问题是在某处显示索引模板,但我不知道为什么

为了提供更多上下文,我的构造函数如下所示:

<?php

require 'Smarty.class.php';

class SmartyEC extends Smarty{

    function SmartyEC()
    {
        function __construct()  
        {
            parent::__construct();
            $appname ='website';
            $path= Utils::getTemplatesPath();   
            $this->caching = false;

        }       

    }
}

?>
但现在的错误是:

未捕获异常“SmartyException”,消息为“无法加载” 中的模板文件“index.tpl” /var/www/vhosts/website/httpdocs/includes/sysplugins/smarty_internal_templatebase.php:127\n堆栈 跟踪:\n#0 /var/www/vhosts/website/httpdocs/includes/sysplugins/smarty_internal_templatebase.php(374): Smarty_Internal_TemplateBase->fetch('index.tpl',NULL,NULL,NULL, 正确)\n#1/var/www/vhosts/website/httpdocs/index.php(58): Smarty_Internal_TemplateBase->display('index.tpl')\n#2{main}\n 投入 /var/www/vhosts/website/httpdocs/includes/sysplugins/smarty_internal_templatebase.php 在线127

更新2


我发现这个主题给出了相同的错误,但情况与这里不同。更有趣的是,在另一台服务器上,它工作正常,因此我猜测这是一个配置问题,而不是编程问题。

您确定
\u construct()
SmartyEC()
中的嵌套吗?(问题,对不起)

如果您明确地将函数命名为public,则错误会立即出现:

class SmartyEC extends Smarty {
    public function SmartyEC()
    {
        public function __construct()  
        {
            parent::__construct();
            $appname ='website';
            $path= Utils::getTemplatesPath();   
            $this->caching = false;
        }
    }
}
给你

Parse error: syntax error, unexpected T_PUBLIC in test.php on line 7

从PHP5开始,我们不再使用类名构造函数。我们使用
\uu construct()
。除非调用
$ec=new SmartyEC()$ec->SmartyEC()明确地在某个地方,应该删除该函数声明:

class SmartyEC extends Smarty {
    public function __construct()  
    {
        parent::__construct();
        $appname ='website';
        $path= Utils::getTemplatesPath();   
        $this->caching = false;
    }
}

还请注意,您的示例调用
$smarty=newsmartyec($page->template)
传递了一个参数,该参数既不是
SmartyEC()
也不是
\uu construct()
所期望的。

最后我得到了它。。。这是由4个不起作用的因素组成的综合体:

  • 我从smarty 3.1.11降级到3.0.7
  • 我找到了另一个与旧主机相关的配置路径- 很容易就修好了
  • .tpl文件包含php代码,如“{php}此处的一些代码{/php}” 并用
    $this->allow\u php\u tag=true将其修复在构造函数中
  • 即使我设置了正确的权限,系统也无法 重写编译文件夹,因此我删除了文件中的所有内容 编译文件夹

  • 请参阅问题中的更新。我尝试了你的两个建议(公开函数声明和删除SmartyEC声明),但是错误现在变了。你看了一下你的构造函数目前做什么了吗<代码>$appname='website'
    $path=Utils::getTemplatesPath()不要自己做太多事情。您可能必须告诉smarty这些值?我还有一系列值,它们在更复杂的验证过程模板\u dir、编译\u dir、配置\u dir和缓存\u dir中初始化,但他们似乎更感兴趣的是,在另一台服务器上,它工作正常,所以我猜这是一个配置问题,而不是编程问题。最终得到了它。无论如何,谢谢你抽出时间!
    
    class SmartyEC extends Smarty {
        public function __construct()  
        {
            parent::__construct();
            $appname ='website';
            $path= Utils::getTemplatesPath();   
            $this->caching = false;
        }
    }