我在某些脚本中发现了这个功能,无法得到它的用途:
class DemoController extends Controller {
public function indexAction() {
$content = include('../index.php');
return array ('content' => $content);
}
}
将PHP脚本包含到变量中有什么用? 这是一种设计模式吗? 任何人都可以朝着正确的方向前进吗?
答案 0 :(得分:5)
我的猜测是index.php
正在构建页面的标记,然后return
。这是生成标记的一种很好的干净方法,并将其作为字符串包含在任何可能想要使用它的脚本中。
请参阅:http://php.net/manual/en/function.include.php#example-158