(जाहिर है मैं नहीं चाहता कि डाटाबेस संपर्क 'मॉडल' चरणों डुप्लिकेट करना चाहते हैं) के बाद से Zend वास्तव में RESTful नहीं है, दुर्भाग्य से, आपका सर्वश्रेष्ठ दांव JSON-RPC है।
आप एक नियंत्रक में कर सकते हैं, या आप बस अपने index.php के अलावा एक ajax.php कर सकते हैं इस आदमी की तरह भूमि के ऊपर कम करने के लिए किया था here
असल में, तुम सब करने की जरूरत है यह है:
$server = new Zend_Json_Server();
$server->setClass('My_Class_With_Public_Methods');
// I've found that a lot of clients only support 2.0
$server->getRequest()->setVersion("2.0");
if ('GET' == $_SERVER['REQUEST_METHOD']) {
// Indicate the URL endpoint, and the JSON-RPC version used:
$server->setTarget('/ajax.php')
->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
// Grab the SMD
$smd = $server->getServiceMap();
// Return the SMD to the client
header('Content-Type: application/json');
echo $smd;
return;
}
$server->handle();
तो अपने लेआउट में कहीं:
$server = new Zend_Json_Server();
$server->setClass('My_Class_With_Public_Methods');
$smd = $server->getServiceMap();
?>
<script>
$(document).ready(function() {
rpc = jQuery.Zend.jsonrpc({
url : <?=json_encode($this->baseUrl('/ajax'))?>
, smd : <?=$smd?>
, async : true
});
});
</script>
उदाहरण के लिए
, यहाँ उस वर्ग है:
class My_Class_With_Public_Methods {
/**
* Be sure to properly phpdoc your methods,
* the rpc clients like it when you do
*
* @param float $param1
* @param float $param2
* @return float
*/
public function someMethodInThatClass ($param1, $param2) {
return $param1 + $param2;
}
}
तो आप बस की तरह तरीकों कॉल कर सकते हैं ताकि जावास्क्रिप्ट में:
rpc.someMethodInThatClass(first_param, second_param, {
// if async = true when you setup rpc,
// then the last param is an object w/ callbacks
'success' : function(data) {
}
'error' : function(data) {
}
});
वहाँ नहीं एंड्रॉयड/iPhone के लिए अच्छी तरह से ज्ञात JSON-RPC पुस्तकालयों का एक बहुत कर रहे हैं - लेकिन मैं ने पाया है कि यह साथ काम करता है Android के लिए Zend_Json_Server:
http://software.dzhuvinov.com/json-rpc-2.0-base.html
और इस iPhone के लिए काम करता है:
http://www.dizzey.com/development/ios/calling-json-rpc-webservice-in-ios/
यहां से, जाहिर है, आप My_Class_With_Public_Methods का उपयोग उसी तरह कर सकते हैं जैसे जावास्क्रिप्ट/आपका मोबाइल ऐप करता है।
क्या तुम यहाँ का उपयोग कर खत्म किया? मैं अभी इसी तरह की स्थिति में हूं। –