0

我想从 zend 控制器 indexAction 调用一个 javascript 函数。我的控制器看起来像这样..

// mycontroller.php

      public function indexAction(){
         $role = 'admin';
         $id = 23;
      // here i want to call the javascript function 
       /// like myjsfun(role, id);
       }

控制器的 viwefile 是 //index.phtml

    here is my javascript function

   <script type='text/javascript'>

   function myjsfun(role, id){
    // code for this function
     }
4

1 回答 1

0

//mycontroller.php

$role = 'admin';
$id = 23;

$this->view->role = $role;
$this->view->id = $id;

//index.phtml

<script type='text/javascript'>

    function myjsfun(role, id){
        // code for this function
    }

    //actual call:
    myjsfun(<?php echo Zend_Json::encode($this->role) ?>, <?php echo Zend_Json::encode($this->id) ?>);
</script>
于 2012-06-13T09:42:07.893 回答