97 lines
2.1 KiB
PHP
97 lines
2.1 KiB
PHP
<?php
|
|
App::uses('AppController', 'Controller');
|
|
/**
|
|
* Logs Controller
|
|
*
|
|
* @property Log $Log
|
|
* @property PaginatorComponent $Paginator
|
|
*/
|
|
class LogsController extends AppController {
|
|
|
|
/**
|
|
* Components
|
|
*
|
|
* @var array
|
|
*/
|
|
public $components = array('Paginator');
|
|
|
|
/**
|
|
* index method
|
|
*
|
|
* @return void
|
|
*/
|
|
public function index() {
|
|
$this->Log->recursive = 0;
|
|
$this->set('logs', $this->Paginator->paginate());
|
|
}
|
|
|
|
/**
|
|
* view method
|
|
*
|
|
* @throws NotFoundException
|
|
* @param string $id
|
|
* @return void
|
|
*/
|
|
public function view($id = null) {
|
|
if (!$this->Log->exists($id)) {
|
|
throw new NotFoundException(__('Invalid log'));
|
|
}
|
|
$options = array('conditions' => array('Log.' . $this->Log->primaryKey => $id));
|
|
$this->set('log', $this->Log->find('first', $options));
|
|
}
|
|
|
|
/**
|
|
* add method
|
|
*
|
|
* @return void
|
|
*/
|
|
public function add() {
|
|
if ($this->request->is('post')) {
|
|
$this->Log->create();
|
|
if ($this->Log->save($this->request->data)) {
|
|
return $this->flash(__('The log has been saved.'), array('action' => 'index'));
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* edit method
|
|
*
|
|
* @throws NotFoundException
|
|
* @param string $id
|
|
* @return void
|
|
*/
|
|
public function edit($id = null) {
|
|
if (!$this->Log->exists($id)) {
|
|
throw new NotFoundException(__('Invalid log'));
|
|
}
|
|
if ($this->request->is(array('post', 'put'))) {
|
|
if ($this->Log->save($this->request->data)) {
|
|
return $this->flash(__('The log has been saved.'), array('action' => 'index'));
|
|
}
|
|
} else {
|
|
$options = array('conditions' => array('Log.' . $this->Log->primaryKey => $id));
|
|
$this->request->data = $this->Log->find('first', $options);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* delete method
|
|
*
|
|
* @throws NotFoundException
|
|
* @param string $id
|
|
* @return void
|
|
*/
|
|
public function delete($id = null) {
|
|
$this->Log->id = $id;
|
|
if (!$this->Log->exists()) {
|
|
throw new NotFoundException(__('Invalid log'));
|
|
}
|
|
$this->request->allowMethod('post', 'delete');
|
|
if ($this->Log->delete()) {
|
|
return $this->flash(__('The log has been deleted.'), array('action' => 'index'));
|
|
} else {
|
|
return $this->flash(__('The log could not be deleted. Please, try again.'), array('action' => 'index'));
|
|
}
|
|
}}
|