API: Zones use Crud for Index and View actions

This commit is contained in:
Kyle Johnson 2015-02-25 10:33:55 -05:00
parent 80b1a61a12
commit 8af8ecb6f1
6 changed files with 1 additions and 48 deletions

View File

@ -4,51 +4,9 @@ App::uses('AppController', 'Controller');
* Zones Controller * Zones Controller
* *
* @property Zone $Zone * @property Zone $Zone
* @property PaginatorComponent $Paginator
*/ */
class ZonesController extends AppController { class ZonesController extends AppController {
/**
* Components
*
* @var array
*/
public $components = array('Paginator', 'RequestHandler');
/**
* index method
*
* @return void
*/
public function index() {
$this->Zone->recursive = -1;
$zones = $this->Zone->find('all');
$this->set(array(
'zones' => $zones,
'_serialize' => array('zones')
));
}
/**
* view method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function view($id = null) {
$this->Zone->recursive = -1;
if (!$this->Zone->exists($id)) {
throw new NotFoundException(__('Invalid zone'));
}
$options = array('conditions' => array('Zone.' . $this->Zone->primaryKey => $id));
$zone = $this->Zone->find('first', $options);
$this->set(array(
'zone' => $zone,
'_serialize' => array('zone')
));
}
// Find all zones which belong to a MonitorId // Find all zones which belong to a MonitorId
public function forMonitor($id = null) { public function forMonitor($id = null) {
$this->loadModel('Monitor'); $this->loadModel('Monitor');

View File

@ -28,6 +28,7 @@ class Zone extends AppModel {
*/ */
public $displayField = 'Name'; public $displayField = 'Name';
public $recursive = -1;
//The Associations below have been created with all possible keys, those that are not needed can be removed //The Associations below have been created with all possible keys, those that are not needed can be removed

View File

@ -1 +0,0 @@
echo json_encode($zones);

View File

@ -1 +0,0 @@
echo json_encode($zone);

View File

@ -1,2 +0,0 @@
$xml = Xml::fromArray(array('response' => $zones));
echo $xml->asXML();

View File

@ -1,2 +0,0 @@
$xml = Xml::fromArray(array('response' => $zone));
echo $xml->asXML();