66 lines
1.8 KiB
PHP
Executable file
66 lines
1.8 KiB
PHP
Executable file
<?php
|
|
class CountriesController extends AppController {
|
|
|
|
var $name = 'Countries';
|
|
var $helpers = array('Html', 'Form');
|
|
|
|
function index() {
|
|
$this->Country->recursive = 0;
|
|
$this->set('countries', $this->paginate());
|
|
}
|
|
|
|
function view($id = null) {
|
|
if (!$id) {
|
|
$this->Session->setFlash(__('Invalid Country.', true));
|
|
$this->redirect(array('action'=>'index'));
|
|
}
|
|
$this->set('country', $this->Country->read(null, $id));
|
|
}
|
|
|
|
function add() {
|
|
$this->set('currencies', $this->Country->Currency->find('list', array('fields'=>array('Currency.id', 'Currency.name'))));
|
|
if (!empty($this->data)) {
|
|
|
|
$this->Country->create();
|
|
|
|
if ($this->Country->save($this->data)) {
|
|
$this->Session->setFlash(__('The Country has been saved', true));
|
|
$this->redirect(array('action'=>'index'));
|
|
} else {
|
|
$this->Session->setFlash(__('The Country could not be saved. Please, try again.', true));
|
|
}
|
|
}
|
|
}
|
|
|
|
function edit($id = null) {
|
|
if (!$id && empty($this->data)) {
|
|
$this->Session->setFlash(__('Invalid Country', true));
|
|
$this->redirect(array('action'=>'index'));
|
|
}
|
|
if (!empty($this->data)) {
|
|
if ($this->Country->save($this->data)) {
|
|
$this->Session->setFlash(__('The Country has been saved', true));
|
|
$this->redirect(array('action'=>'index'));
|
|
} else {
|
|
$this->Session->setFlash(__('The Country could not be saved. Please, try again.', true));
|
|
}
|
|
}
|
|
if (empty($this->data)) {
|
|
$this->data = $this->Country->read(null, $id);
|
|
}
|
|
}
|
|
|
|
function delete($id = null) {
|
|
if (!$id) {
|
|
$this->Session->setFlash(__('Invalid id for Country', true));
|
|
$this->redirect(array('action'=>'index'));
|
|
}
|
|
if ($this->Country->del($id)) {
|
|
$this->Session->setFlash(__('Country deleted', true));
|
|
$this->redirect(array('action'=>'index'));
|
|
}
|
|
}
|
|
|
|
}
|
|
?>
|