Heim  >  Artikel  >  Backend-Entwicklung  >  thinkphp模板使用问题

thinkphp模板使用问题

WBOY
WBOYOriginal
2016-06-23 14:18:59870Durchsuche

在thinkphp里面结合使用smarty模板,都已经配置好了,在IndexAction.class.php文件里面使用$this->display("login")没有问题,但是另外一个文件DefaultAction.class.php文件里面同样使用,则出现以下问题:
Fatal error: Call to a member function display() on a non-object in E:\php\AppServ\www\DLP\ThinkPHP\Lib\Think\Core\Action.class.php on line 103

其中Action.class.php那边的代码是:

    protected function display($templateFile='',$charset='',$contentType='text/html')
    {echo $templateFile;
        if(false === $templateFile) {
            $this->showTrace();
        }else{
            $this->view->display($templateFile,$charset,$contentType);
        }
    }

有没有出现过同样问题的大哥,给个帮助...


回复讨论(解决方案)

应该是 DefaultAction.class.php 这个文件的问题,你看下它的类名以及继承类名是否正确

应该不是tp里的错误,而是你控器中哪个display引用出了问题,好好检查一下。

我也出现过,因为Action用了构造函数
function __construct()
{
  //content
}

在TP中要用

function __construct()
{
  parent::__construct;
}

我也出现过,因为Action用了构造函数
function __construct()
{
  //content
}

在TP中要用

function __construct()
{
  parent::__construct;
}
正解

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn