【发布时间】:2014-02-27 07:57:33
【问题描述】:
美好的一天。
我们有 3 个文件:
1) index.php
<?php
require_once("functions.php");
$t= new getgunctions;
$t->getgainTpl();
$t->controllerTpl(1);
?>
2) functions.php
<?php
class getgunctions{
.....
public function controllerTpl(){
$this->form();
}
private function form(){
include "form.tpl";
}
public function right(){
echo 'test';
}
.....
}
?>
3) form.tpl
<div><?php $this->right(); ?></div>
但我得到错误:Using $this when not in object context...
请告诉我如何正确使用form.tpl中的函数right();?
【问题讨论】:
-
你不能在类/对象方法之外使用
$this -
尝试在包含 form.tpl 之前添加“$obj = $this;”,并使用 $obj->right()
-
在
form.tpl中包含functions.php并在functions.php中使用类名而不是$this