我一直在调查 Lithium PHP Framework我不明白它是如何设置 $this->context;
( particularly in this layout .)
因为你不能简单地重新分配 $this
显然这个布局会在某个时候被包含进来,更让我困惑的是他们在外面使用 $this
类定义。
我有一段时间没有编写 PHP 代码了,所以请在这里帮助我。
最佳答案
让我印象深刻的第一个想法是这个模板页面是从一个方法中调用的。
class Viewer
{
public $html;
private $title;
private $content;
public function __construct()
{
$this->html = new \Utilities\HTMLBag();
}
public function loadView($template)
{
ob_start();
include 'path/to/views/'.$template.'.php';
$this->content = ob_get_clean();
}
public function title()
{
return $this->title;
}
}
从这点来看,包含的$template
可以访问Viewer类的任何方法
关于php - lithium PHP 框架如何在 PHP 页面中生成 $this 上下文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13510068/