Created
June 27, 2011 16:46
-
-
Save eminetto/1049258 to your computer and use it in GitHub Desktop.
ApiController
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ApiController extends Zend_Rest_Controller | |
{ | |
public function init() | |
{ | |
$this->_helper->viewRenderer->setNoRender(true); | |
$this->_helper->layout()->disableLayout(); | |
if($this->getRequest()->getHeader('apiKey') != 'chave1') { | |
$this->getResponse() | |
->setHttpResponseCode(403) | |
->appendBody("Invalid API Key\n"); | |
$this->getRequest()->setModuleName('default') | |
->setControllerName('index') | |
->setActionName('index') | |
->setDispatched(true); | |
} | |
} | |
public function indexAction() { | |
} | |
public function getAction() | |
{ | |
$id = $this->_getParam('id'); | |
if(isset($id)) { | |
$content = Content::find($id); | |
$data = array(); | |
$data['id'] = $id; | |
foreach($content->getPropertyKeys() as $k) { | |
if(is_string($content->$k)) | |
$data[$k] = $content->$k; | |
} | |
} | |
else { | |
$params = $this->_getAllParams(); | |
unset($params['controller']); | |
unset($params['action']); | |
unset($params['module']); | |
$content = Content::all($params); | |
$data = array(); | |
foreach($content as $c) { | |
$d[] = array(); | |
$d['id'] = $id; | |
foreach($c->getPropertyKeys() as $k) { | |
if(is_string($c->$k)) | |
$d[$k] = $c->$k; | |
} | |
$data[] = $d; | |
} | |
} | |
echo json_encode($data); | |
} | |
public function postAction() { | |
} | |
public function putAction() | |
{ | |
} | |
public function deleteAction() | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment