【发布时间】:2013-10-17 02:22:47
【问题描述】:
我有以下型号:
class Person
{
public $name;
function __Construct( $name )
{
$this->name = $name;
}
}
我有以下控制器:
class NavigationController extends Controller
{
public function indexAction()
{
$people = array(
new Person("James"),
new Person("Bob")
);
return $this->render('FrameworkBundle:Navigation:index.html.php', $people);
}
}
如何访问视图中的模型数组。有没有办法直接访问模型或者我必须像这样分配一个属性:?
class NavigationController extends Controller
{
public function indexAction()
{
$people = array(
new Person("James"),
new Person("Bob")
);
return $this->render('FrameworkBundle:Navigation:index.html.php', array( "model" => $people ) );
}
}
查看:
<?php
foreach( $model as $person )
{
echo $person->title;
}
?>
上面的问题是用户可以将其更改为
return $this->render( 'FrameworkBundle:Navigation:index.html.php', array( "marybloomingpoppin" => $people ) );
【问题讨论】:
标签: php symfony domain-object