0

ビューで、Student という変数を定義します。私の見解では、Student オブジェクトを JSON として表示するにはどうすればよいですか?

public function previewAction()
{
    // ... 
    $this->view->student = $student;
}

私の preview.phtml ビューには、次のものがあります。

<script>
    // this doesn't return the Application_Model as a JSON object in the html       
    var studentData = <?php echo Zend_Json::encode($this->student); ?>; 
</script>
4

1 に答える 1

1

PHPタグを引用符で囲みます

<script>
    // this doesn't return the Application_Model as a JSON object in the html       
    var studentData = "<?php echo Zend_Json::encode($this->student); ?>"; 
</script>
于 2012-05-11T15:05:51.917 に答える