这样的功能背后可能是什么实用的想法



我在某些脚本中找到了此功能,无法得到它的用途:

    class DemoController extends Controller {
        public function indexAction() {
          $content = include('../index.php');
          return array ('content' => $content);
    }
}

将PHP脚本包括在变量中的用途是什么?这是一种设计模式吗?任何人都可以开车到正确的方向?

我的猜测是 index.php正在为页面的标记构建标记,然后 return in Ing。这是一种生成标记并将其作为字符串包含在脚本中的脚本的好方法。

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

最新更新