php - lithium PHP 框架如何在 PHP 页面中生成 $this 上下文?

标签 php frameworks views lithium

我一直在调查 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/

相关文章:

objective-c - 网络扩展 - NEVPNManager

ios - Swift3 框架模块为空

ios - 警告 : ignoring file . ./lib/mobileRTC.framework/mobileRTC,文件 ../lib/mobileRTC.framework/mobileRTC 中缺少所需的体系结构 x86_64

ruby-on-rails - rails : Using local variable for an image path

php - 使用 strtotime() 和 date() 更改日期时间格式时导致特定日期时间的空值

javascript - MIT APP Inventor 打开时出错。如何解决?

View 和 $this 中的 Cakephp 助手

sql-server - SQL Server 中的 sp_depends,可能的依赖关系是什么?

php - 如何显示我存储在数组中的 ID 详细信息?

Php artisan 制作:auth not defined in Laravel 9