ACC SHELL
<?php
class UsersController extends AppController
{
//var $scaffold;
var $name = 'Users';
function index() {
$this->User->recursive = 0;
$this->set('users', $this->User->findAll());
}
function add() {
if(empty($this->data)) {
$this->set('users', null);
} else {
$this->cleanUpFields();
if($this->User->save($this->data)) {
if(is_object($this->Session)) {
$this->Session->setFlash('The User has been saved');
$this->redirect($this->viewPath.'/index');
} else {
$this->flash('User saved.', $this->viewPath.'/index');
}
} else {
if(is_object($this->Session)) {
$this->Session->setFlash('Please correct errors below.');
}
$data = $this->data;
$this->set('users', $data);
}
}
}
function edit($id) {
if(empty($this->data)) {
$data = $this->User->read(null, $id);
$this->set('users', $data );
} else {
$this->cleanUpFields();
if($this->User->save($this->data)) {
if(is_object($this->Session)) {
$this->Session->setFlash('The User has been saved');
$this->redirect($this->viewPath.'/index');
} else {
$this->flash('User saved.', $this->viewPath.'/index');
}
} else {
if(is_object($this->Session)) {
$this->Session->setFlash('Please correct errors below.');
}
$data = $this->data;
$this->set('users', $data);
}
}
}
function view($id) {
$this->set('users', $this->User->read(null, $id));
}
function delete($id) {
$this->User->del($id);
$this->redirect('/users/index');
}
}
?>
ACC SHELL 2018