Foil PHP致命错误:在不在对象中时使用$ this

时间:2017-08-31 13:40:09

标签: php

我第一次使用Foil PHP。 我已经阅读了所有文档,但定义部分给我带来了这个错误: 致命错误:不在对象中时使用$ this

我也在doc(http://www.foilphp.it/docs/TEMPLATES/INHERITANCE.html

中完全尝试了这个例子
    <!DOCTYPE html>
<html>
    <head>
        <?php $this->section('head') ?>
          <link rel="stylesheet" href="style.css" />
          <title><?php $this->section('title') ?>My Home Page<?php $this->stop() ?></title>
        <?php $this->stop() ?>
    </head>
    <body>
        <div id="content">
          <?php $this->section('content') ?>
          <?php $this->stop() ?>
        </div>
        <div id="footer">
          <?php $this->section('footer') ?>
            &copy; Copyright 2014 by <a href="http://example.com/">you</a>.
          <?php $this->stop() ?>
        </div>
    </body>
</html>

但它给了我$ this上下文致命错误。 使用$ engine-&gt;渲染来渲染填充了html内容的模板。

请帮帮我:(

1 个答案:

答案 0 :(得分:1)

您是直接访问此内容吗?那不行。 $这只适用于INSIDE一个类:

<?php

class Thing
{
    private $x;

   public function getValue()
   {
        return $this->x;
   }
}

您应该从引擎渲染模板。