2012-06-13 85 views
0

我想从zend控制器indexAction调用一个javascript函数。我的控制器看起来像这样..如何从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 
    } 

回答

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> 
+0

谢谢..我可以调用控制器内的函数,如

+0

否。语法不正确(PHP变量需要'$'),并且您没有变量'$ role'和'$ id'。我提出的代码有什么问题? – bububaba

相关问题