の問題は何ですか?
/**
* Say Hello
*
* @param string $who
* @param string $when
* @return string
*/
function sayHello($who, $when)
{
return "Hello $who, Good $when";
}
$server = new Zend_Rest_Server();
$server->addFunction('sayHello');
$server->handle();
あなたは特に問題はありませんか?Zend_Rest_Serverを使用する方法に関する絶対的な最小例がありますか?
EDIT: これはあなたがWebサービスのために必要としない多くの機能と一緒にEXTREMのオーバーヘッドを導入することを、私は思うMVCの統合に関するご質問について。それにもかかわらず、大きなオーバーヘッドがなくても、MVCにサービスを統合することは可能です。
class Hello
{
/**
* Say Hello
*
* @param string $who
* @param string $when
* @return string
*/
function sayHello($who, $when)
{
return "Hello $who, Good $when";
}
}
class ApiController extends Zend_Controller_Action
{
/**
* @var Zend_Rest_Server
*/
protected $_server;
public function init()
{
// disable view rendering
$this->_helper->viewRenderer->setNeverRender(true);
// disable layout (if you use layouts)
$this->_helper->layout->disableLayout();
$this->_server = new Zend_Rest_Server();
$this->_server->setClass('Hello');
}
public function __call($method, $args)
{
$params = $this->_getAllParams();
$params['method'] = $method;
$this->_server->handle($params);
}
}
/*
* This should allow you to call http://www.example.com/api/sayHello/who/MyName/when/morning
* By defining custom routes you're able to control the urls.
*/
コードがテストされていないと確実に特にエラー処理に関するいくつかの調整を必要とするが、それは簡単なMVCのサービスの例として使用できることに注意してください。
MVCでの使用方法の良い例が見つかりませんでした。あなたはコントローラの中でそれをする方法を私に見せてもらえますか? – wenbert
ありがとうございます。私は十分な評判を持っていれば、私はupvoteするだろう:)答えを本当に感謝:D – wenbert
JUstは明確にする:あなたはしていない他のZend Frameworkコンポーネントを使用するだけでMVCを使用する必要があります。このようにして、Zend Frameworkは他のPHPフレームワークほど厳密ではありません。これは単なるコンポーネント間の依存関係ではありません。 –