我有以下模型:
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 ) );