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

mix*_*_ru 5 php function

我在一些脚本中找到了这个功能,但无法得到它的用途:

    class DemoController extends Controller {

        public function indexAction() {

          $content = include('../index.php');
          return array ('content' => $content);
    }
}
Run Code Online (Sandbox Code Playgroud)

将php脚本包含到变量中有什么用?这是一种设计模式吗?谁能开车到正确的方向?

谢谢!

Sea*_*son 5

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

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