2012-01-26 29 views
0

Zend's JSON-RPC server似乎並不喜歡會話,即使將Zend_Session::getId()傳遞給我的RPC方法,我也不能附加一個會話,並按照我的預期將其恢復爲Zend_Session::setId($session_id)如何在Zend_Json_Server中使用Zend_Auth?

爲了說明什麼行不通:

<?php 

$server = new Zend_Json_Server(); 
$server->setClass('MyRPC'); 
?> 
<script> 
$(document).ready(function() { 
    myrpc = jQuery.Zend.jsonrpc({ 
     url : <?=json_encode($this->baseUrl('/ajax'))?> 
     , smd : <?=$server->getServiceMap()?> 
     , async : true 
    }); 
    myrpc.getIdentity(<?=json_encode(Zend_Session::getId())?>, { 
     success : function(data) { 
      alert(data.user_id); 
     } 
    }); 
}); 
// see: http://www.tanabi.com/projects/jsonrpc 

</script> 

,並在我的RPC類:

<?php 

class MyRPC { 

    /** 
    * @param string 
    * @return array 
    */ 
    public function getIdentity($session_id) { 
     \Zend_Session::setId($session_id); 
     \Zend_Session::start(); 
     // returns NULL 
     return \Zend_Auth::getInstance()->getIdentity(); 
    } 

} 

回答