ACC SHELL
<?php
class OborPodnikaniController extends TF_Controller_Action
{
/**
* The default action - show the home page
*/
public function indexAction ()
{
$model = new BusinessScope();
$this->view->data = $model->getAll(array());
}
public function upravitAction()
{
$id = $this->_getParam('id',-1);
$model = new BusinessScope();
$item = $model->find($id)->current();
$form = $this->view->form = new Form_BusinessScope();
if ($this->_request->isPost()) {
if ($form->isValid($_POST)) {
$vals = (object)$form->getValues();
$item->name = $vals->name;
$item->save();
$this->_addFlashMessage('Upraveno');
$this->_helper->redirector('index');
}
} else {
$form->populate($item->toArray());
}
}
public function pridatAction()
{
$model = new BusinessScope();
$item = $model->createRow();
$form = $this->view->form = new Form_BusinessScope();
if ($this->_request->isPost()) {
if ($form->isValid($_POST)) {
$vals = (object)$form->getValues();
$item->name = $vals->name;
$item->save();
$this->_addFlashMessage('Přidáno');
$this->_helper->redirector('index');
}
}
}
public function smazatAction()
{
$id = $this->_getParam('id',-1);
$model = new BusinessScope();
$item = $model->find($id)->current();
try{
$item->delete();
$this->_addFlashMessage('Smazáno');
} catch (Zend_Db_Exception $e) {
if (strpos($e->getMessage(), 'SQLSTATE[HY000]: General error: 1451') !== false) {
$this->_addFlashMessage('Tento záznam nelze smazat. Pravděpodobně existují záznamy v jiných tabulkách, které ho používají.', 'error');
} else {
throw $e;
}
}
$this->_helper->redirector('index');
}
}
ACC SHELL 2018