我想在echo'd渲染类中访问字符串。
控制器文件:
$Page = new Page;
$string = "Some data here...";
echo $Page->render();
body.php:
<body>
echo '<p>'.$string.'</p>'; //$string returns as
</body>
渲染:
class Page
{
public function render(){
include 'header.php';
include 'body.php';
include 'footer.php';
}
}
答案 0 :(得分:0)
通常在这些情况下,值通过参数发送。类似的东西:
$Page = new Page;
echo $Page->render(array(
"string" => "Some data here...",
"other_variable" => "Some other value here",
));
然后在渲染方法中使用这些值:
class Page
{
public function render($values) {
extract($values);
include 'header.php';
include 'body.php';
include 'footer.php';
}
}
请记住,这只是一个非常简单的示例,仅用于演示目的!