0

私は次のモデルを持っています:

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 ) );
4

1 に答える 1