这样一个功能背后可能有什么实际的想法?

时间:2015-05-04 09:15:56

标签: php function

我在某些脚本中发现了这个功能,无法得到它的用途:

    class DemoController extends Controller {

        public function indexAction() {

          $content = include('../index.php');
          return array ('content' => $content);
    }
}

将PHP脚本包含到变量中有什么用? 这是一种设计模式吗? 任何人都可以朝着正确的方向前进吗?

1 个答案:

答案 0 :(得分:5)

我的猜测是index.php正在构建页面的标记,然后return。这是生成标记的一种很好的干净方法,并将其作为字符串包含在任何可能想要使用它的脚本中。

请参阅:http://php.net/manual/en/function.include.php#example-158