-
Notifications
You must be signed in to change notification settings - Fork 37
Controller Crud
Контроллер который класс, реализует CRUD - Create/Read/Update/Delete наших сущностей, требует реализованный Crud класс.
GET <has PK> -Y-> <it is> -N-> [error]
| |
N Y
| |
[create form] [edit form]
POST <create> -Y-> [success]
|
N
|
[create form]
[error stack]
PUT <save> -Y-> [success]
|
N
|
[edit form]
[error stack]
DELETE <it is> -N-> [error]
|
Y
|
[success]
Нет
Данный класс можно обернуть в анонимную функцию-контроллер:
<?php
return function() {
$crudController = new Controller\Crud();
$crudController->setCrud(Model\Crud::getInstance());
return $crudController();
};
Либо использовать как есть:
<?php
$crudController = new Controller\Crud();
$crudController->setCrud(Model\Crud::getInstance());
return $crudController;
Для данного контроллера следует реализовать один шаблон, который должен представлять из себя форму создания/редактирования элемента, для формы редактирования Id элемента должен передаваться в URL:
<?php $uid = uniqid('form_'); ?>
<form id="<?=$uid?>" action="<?=$this->url('test', 'crud')?>/<?=$row->id?>" class="form-horizontal ajax" method="<?=$method?>">
<div class="modal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3>Test Table</h3>
</div>
<div class="modal-body">
<div class="control-group">
<label class="control-label" for="name"><?=$this->__('Name')?></label>
<div class="controls">
<input type="text" class="input-xlarge" id="name" name="name" value="<?=($row->name)?>" />
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary"><?=$this->__('Save')?></button>
<a href="#" class="btn" data-dismiss="modal"><?=$this->__('Close')?></a>
</div>
</div>
</form>
Теперь можно создавать кнопки для редактирования и удаления сущностей на любой странице:
<!-- create button -->
<a href="<?=$this->url('test', 'crud')?>" class="btn dialog" data-ajax-method="get">Create</a>
<!-- edit button -->
<a href="<?=$this->url('test', 'crud');?>/123" class="btn dialog" data-ajax-method="get">Edit</a>
<!-- delete button -->
<a href="<?=$this->url('test', 'crud');?>/123" class="confirm btn btn-danger ajax" data-ajax-method="delete">Delete</a>
Для CRUD контроллера лучше всего описать привилегию
Managmentи проверять её посредством функционала заложенного в помощникеurl()
Acl
Application
Auth
Cache
Common
— Exception
— Collection
— Container
— Helper
— Options
— Singleton
Config
Controller
— Data
— Mapper
—— Crud
—— Rest
— Reflection
Crud
— Crud Table
Db
— Row
— Table
— Relations
— Query
Debug
EventManager
Grid
Http
Layout
Logger
Mailer
Messages
Nil
Proxy
Registry
Request
Response
Router
Session
Translator
Validator
View