Crud

Application development on steroids

by Christian "Jippi" Winther / @jippi
GitHub: friendsofcake/crud / FriendsOfCake.com/crud

What is CRUD?

  • - [C]reate
  • - [R]read
  • - [U]pdate
  • - [D]elete

CRUD v2

The Nodes version

  • - One big Component class
  • - Not flexible
  • - Hidden bugs
  • - Almost no documentation
  • - Not (really) maintained
  • - Inconsistent
  • - Not very well unit tested
  • - Bad architecture
  • - Not community backed


It worked really well when I did it

CRUD v3

The current version

  • - Separate classes for each Crud action
  • - Very flexible
  • - No known bugs
  • - Tons of documentation
  • - Actively maintained (6 CakePHP core devs)
  • - Very consistent
  • - 90% test coverage
  • - Clean architecture
  • - Community backed


Rewritten from scratch

The Crud Component

Very very skinny

Most logic is moved into Crud Actions & Listeners

v2 => v3

Didn't spend time making upgrade easy

It just happened to be very similar APIs

v2 => v3

All "map*" configs are gone

No "actionMap", "viewMap", "findMethodMap" or "listenerClassMap"

v2 => v3

getListener()


// v2
$this->Crud->getListener($name);
// v3
$this->Crud->listener($name);
					

v2 => v3

trigger()


// v2
$this->Crud->trigger($name);
// v3
// also support array of $name, and event priority
$this->Crud->trigger($name);
					

Same, but better, yay!

v2 => v3

enableAction()


// v2
$this->Crud->enableAction($name);
// v3
// also support array of $name
$this->Crud->enable($name);
					

v2 => v3

disableAction()


// v2
$this->Crud->disableAction($name);
// v3
// also support array of $name
$this->Crud->disable($name);
					

v2 => v3

mapActionView()


// v2
$this->Crud->mapActionView('edit', 'form');
// v3
$this->Crud->action('edit')->view('form');
// v3
$this->Crud->action('edit')->config('view', 'form');
					

v2 => v3

mapAction()


// v2
$this->Crud->mapAction($action, $type, $enable = true);
// v3
$this->Crud->mapAction($action, $type, $enable = true);
					

Same, yay

v2 => v3

isActionMapped()


// v2
$this->Crud->isActionMapped($action);
// v3
$this->Crud->isActionMapped($action);
					

Same, yay

v2 => v3

mapFindMethod()


// v2
$this->Crud->mapFindMethod('view', 'first');
// v3
$this->Crud->action('view')->findMethod('first');
// v3
$this->Crud->action('view')->config('findMethod', 'first');
					

v2 => v3

on()


// v2
$this->Crud->on($events, $callback);
// v3
$this->Crud->on($events, $callback);
					

Same, yay

v2 => v3

config()


// v2
$this->Crud->config($key, $value);
// v3
$this->Crud->config($key, $value);
					

Same, yay

This only changes CrudComponent settings now, not actions

v2 => v3

executeAction()


// v2
$this->Crud->executeAction($controllerAction, $args);
// v3
$this->Crud->executeAction($controllerAction, $args);
					

Same, yay

Crud Actions

No longer _[index|add|edit|view|delete]Action method in CrudComponent


_${name}Action => Plugin/Crud/Controller/Crud/Action/${name}CrudAction

Crud actions

One class per action

Share nothing

Isolated configuration

Crud actions

  • Index
  • View
  • Add
  • Edit
  • Delete
  • {Your own action here}

Index Crud action


class IndexCrudAction extends CrudAction {

	protected $_settings = [];

	protected function _get() {}

}
					

Add Crud action


class AddCrudAction extends CrudAction {

	protected $_settings = [];

	protected function _get() {}

	protected function _post() {}

	protected function _put() {}

}
					

YOUR Crud action


class YourCrudAction extends CrudAction {

	protected $_settings = [];

	protected function _get() {}

	protected function _post() {}

	protected function _put() {}

}
					

YOUR Crud action


class YourCrudAction extends CrudAction {

	protected $_settings = [];

	protected function _handle() {}

}
					

Crud listeners

One class per listener

Share nothing

Isolated configuration

Listen for events

Crud listeners

  • Search
  • DebugKit
  • Scaffold
  • Related Models
  • Api
  • Api QueryLog
  • Api Pagination
  • Api Field Filter
  • Api Transformation

This will break

  • Export Component (view class or listener)
  • Controller::$paginate (deprecated in CakePHP)

Future of Crud

Crud View


On the fly views for all build-in & user provided crud actions.


Admin interface for free.

Future of Crud

Batch operations


[Add|Edit|Delete] multiple records

Thank you

Questions?

Code?

Discuss!


by Christian "Jippi" Winther / @jippi
GitHub: friendsofcake/crud / cakephp.nu