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 に答える