제가하려는 것은 $ rest-> apikey를 내 Zend_Rest_Server에 전달하는 것입니다. empAction은 내 Zend_Rest_Server에 필요한 배열을 만듭니다. 하지만 getByShortname ($ id, $ apikey)에서는 $ apikey를 읽을 수 없습니다. API 키를 확인하기 위해 쿼리를 실행해도 결과가 반환되지 않습니다.Zend_Rest_Server + Zend_Rest_Client, 변수가 읽히지 않습니다.
$rest = new Zend_Rest_Client('http://localhsot/api/emp');
$rest->method('getByShortname');
$rest->id('1124921');
$rest->apikey('1234');
$result = $rest->get();
var_dump($result); //should work
//---------------------------------------
//For Emp method--> api/emp
//---------------------------------------
//... rest of code ...
public function empAction()
{
require_once 'EmprestServer.php';
$params = $this->_getAllParams();
unset($params['controller']);
unset($params['action']);
unset($params['module']);
$param_keys = array_keys($params);
if($param_keys[0]=='id') {
$request = array('method' => 'getById');
} else if($param_keys[0]=='shortname') {
$request = array('method' => 'getByShortname');
}
foreach($param_keys AS $key) {
$request[$key] = $filter_params[$key]; //need to filter key
//need better checking
if(!$request[$key]) {
throw new Exception($request[$key].' contained invalid data.');
}
}
/*
I am able to generate this array using the code prior to this line...
$request = array();
$request['method'] = 'getByShortname';
$request['shortname'] = 'wdelrosa';
$request['apikey'] = '1234';
*/
$server = new Zend_Rest_Server();
$server->setClass('EmprestServer');
$server->handle($request);
}
//... rest of code ...
//---------------------------------------
//The Class
//---------------------------------------
class EmprestServer
{
public function getByShortname($shortname,$apikey)
{
$emp = new Employee();
$data = array();
/** PROBLEM **/
/** I can't access $apikey WHY? Any ideas? **/
if(!$this->checkKey($apikey)) {
throw new Exception('Key is invalid.');
}
if(!$data = $emp->getEmployeeByShortname($shortname)) throw new Exception('Employee ID not found.');
$data = $data->toArray();
return $data;
}
}
업데이트 : 이것은 작동하는 것 같습니다. 이걸로 유효한 XML 출력을 얻었습니다.
http://locahost/api/emp/shortname/wdelrosa/apikey/1234
위의 Zend_Rest_Client를 사용하면 apikey가 읽히지 않습니다.
일부 코드를 놓친 것 같습니다. getByShortname의 ID는 어디서 오는가? 그 짧은 이름이 필요하지 않습니까? –
getByEmployeeByShortname ($ shortname)에 getByEmployee ($ id)를 편집했습니다 ... 여기서 $ shortname이 함수에 전달되었습니다. – wenbert