public function getNetwork($id = null) { if (!$this->Organization->exists($id)) { throw new NotFoundException(__('Invalid organization')); } $options = array('conditions' => array('Organization.' . $this->Organization->primaryKey => $id)); $this->set('organization', $this->Organization->find('first', $options)); APP::import('Model','Network'); $this->Network = new Network; $results = $this->apiNetwork($id); foreach($results as $result){ $data = array( 'id' => $result->id, 'name' => $result->name, 'organization_id' => $result->organizationId, 'timeZone' => $result->timeZone, 'tags' => $result->tags, 'type' => $result->type ); $this->Network->save($data); } return $this->redirect(array('controller' => 'networks','action' => 'index')); }