PHP Class CrudComponent, Platform-Crud-Plugin

Scaffolding on steroids! :) Copyright 2010-2012, Nodes ApS. (http://www.nodesagency.com/) Licensed under The MIT License Redistributions of files must retain the above copyright notice.
See also: http://book.cakephp.org/2.0/en/controllers/components.html#Component
Inheritance: extends Component
Afficher le fichier Open project: nodesagency/Platform-Crud-Plugin Class Usage Examples

Méthodes publiques

Свойство Type Description
$components array Reference to a Session component
$settings array validateId ID Argument validation - by default it will inspect your model's primary key and based on it's data type either use integer or uuid validation. Can be disabled by setting it to "false". Supports "integer" and "uuid" configuration By default it's configuration is NULL, which means "auto detect" eventPrefix All emitted events will be prefixed with this property value secureDelete delete() can only be called with the HTTP DELETE verb, not POST when true. If set to false HTTP POST is also acceptable actions contains an array of controller methods this component should offer implementation for. The actions is used for actionMap, viewMap and findMethodMap to change behavior of CrudComponent By default no actions are enabled translations is the settings for the translations Event, responsible for the text used in flash messages see TranslationsEvent::$_defaults the full list of options relatedList is a map of the controller action and the whether it should fetch associations lists to be used in select boxes. An array as value means it is enabled and represent the list of model associations to be fetched saveAllOptions Raw array passed as 2nd argument to saveAll() in add and edit method If you configure a key with your action name, it will override the default settings. This is useful for adding fieldList to enhance security in saveAll. actionMap A map of the controller action and what CRUD action we should call. By default it supports non-prefix and admin_ prefixed routes viewMap A map of the controller action and the view to render By default it supports non-prefix and admin_ prefixed routes findMethodMap The default find method for reading data listenerClassMap List of internal-name => ${plugin}.${class} listeners that will be bound automatically in Crud. By default translations and related model events are bound. Events will always assume to be in the Controller/Event folder

Protected Properties

Свойство Type Description
$_action string The current controller action
$_controller Controller Reference to the current controller
$_eventManager CakeEventManager Reference to the current event manager
$_listeners array List of listener objects attached to Crud
$_model Model Cached property for the current Controller::modelClass instance
$_modelName string Cached property for Controller::modelClass
$_request CakeRequest Reference to the current request

Méthodes publiques

Méthode Description
__construct ( ComponentCollection $collection, array $settings = [] ) Constructor
config ( mixed $key = null, mixed $value = null ) : TranslationsEvent Generic config method
disableAction ( string $action ) : void Disable a CRUD action
enableAction ( string $action ) : void Enable a CRUD action
executeAction ( string $controllerAction = null, $args = [] ) : mixed Execute a Crud action
getIdFromRequest ( ) : string Helper method to get the passed ID to an action
getListener ( string $name, $create = true ) : CrudBaseEvent Get a single event class
initialize ( Controller $controller ) : void Make sure to update the list of known controller methods before startup is called
isActionMapped ( string | null $action = null ) : boolean Check if a CRUD action has been mapped (aka should be handled by CRUD component)
mapAction ( string $action, string $type, boolean $enable = true ) : void Map action to a internal request type
mapActionView ( string | array $action, string $view = null ) : void Map the view file to use for a controller action
mapFindMethod ( string $action, strign $method ) : void Map a controller action to a Model::find($method)
on ( string | array $events, callback $callback ) : void Attaches an event listener function to the controller for Crud Events
trigger ( string $eventName, array $data = [] ) : CrudSubject Triggers a Crud event by creating a new subject and filling it with $data if $data is an instance of CrudSubject it will be reused as the subject object for this event.

Méthodes protégées

Méthode Description
_addAction ( ) : void Generic add action
_deleteAction ( string $id = null ) : void Generic delete action
_detectPrimaryKeyFieldType ( ) : string Automatically detect primary key data type for _validateId()
_editAction ( string $id = null ) : void Generic edit action
_getFindMethod ( string | null $action = null, string | null $default = null ) : string Get the model find method for a current controller action
_getResourceName ( ) : string Return the human name of the model
_getSaveAllOptions ( string | null $action = null ) : array Build options for saveAll
_getSubject ( array $additional = [] ) : CrudSubject Create a CakeEvent subject with the required properties
_indexAction ( ) : void Generic index action
_loadListener ( string $name ) : void Load a single event class attached to Crud
_loadListeners ( ) : void Load all event classes attached to Crud
_redirect ( CrudSubject $subject, array | null $url = null ) : void Called for all redirects inside CRUD
_setFlash ( string $type ) : void Wrapper for Session::setFlash
_setModelProperties ( ) : void Set internal model properties from the controller
_validateId ( mixed $id ) : boolean Is the passed ID valid ?
_viewAction ( string $id = null ) : void Generic view action

Method Details

__construct() public méthode

Constructor
public __construct ( ComponentCollection $collection, array $settings = [] )
$collection ComponentCollection A ComponentCollection this component can use to lazy load its components
$settings array Array of configuration settings.

_addAction() protected méthode

Triggers the following callbacks - Crud.init - Crud.beforeSave - Crud.afterSave - Crud.beforeRender
protected _addAction ( ) : void
Résultat void

_deleteAction() protected méthode

Triggers the following callbacks - beforeFind - recordNotFound - beforeDelete - afterDelete
protected _deleteAction ( string $id = null ) : void
$id string
Résultat void

_detectPrimaryKeyFieldType() protected méthode

Binary or string with length of 36 chars will be detected as UUID If the primary key is a number, integer validation will be used If no reliable detection can be made, no validation will be made
protected _detectPrimaryKeyFieldType ( ) : string
Résultat string

_editAction() protected méthode

Triggers the following callbacks - Crud.init - Crud.beforeSave - Crud.afterSave - Crud.beforeFind - Crud.recordNotFound - Crud.afterFind - Crud.beforeRender
protected _editAction ( string $id = null ) : void
$id string
Résultat void

_getFindMethod() protected méthode

Get the model find method for a current controller action
protected _getFindMethod ( string | null $action = null, string | null $default = null ) : string
$action string | null The controller action
$default string | null The default find method in case it haven't been mapped
Résultat string The find method used in ->_model->find($method)

_getResourceName() protected méthode

By default it uses Inflector::humanize, but can be changed using the "name" configuration property
protected _getResourceName ( ) : string
Résultat string

_getSaveAllOptions() protected méthode

Merges defaults + any custom options for the specific action
protected _getSaveAllOptions ( string | null $action = null ) : array
$action string | null
Résultat array

_getSubject() protected méthode

Create a CakeEvent subject with the required properties
protected _getSubject ( array $additional = [] ) : CrudSubject
$additional array Additional properties for the subject
Résultat CrudSubject

_indexAction() protected méthode

Triggers the following callbacks - Crud.init - Crud.beforePaginate - Crud.afterPaginate - Crud.beforeRender
protected _indexAction ( ) : void
Résultat void

_loadListener() protected méthode

Load a single event class attached to Crud
protected _loadListener ( string $name ) : void
$name string
Résultat void

_loadListeners() protected méthode

Load all event classes attached to Crud
protected _loadListeners ( ) : void
Résultat void

_redirect() protected méthode

Called for all redirects inside CRUD
protected _redirect ( CrudSubject $subject, array | null $url = null ) : void
$subject CrudSubject
$url array | null
Résultat void

_setFlash() protected méthode

Wrapper for Session::setFlash
protected _setFlash ( string $type ) : void
$type string Message type
Résultat void

_setModelProperties() protected méthode

Set internal model properties from the controller
protected _setModelProperties ( ) : void
Résultat void

_validateId() protected méthode

By default we assume you want to validate an numeric string like a normal incremental ids from MySQL Change the validateId settings key to "uuid" for UUID check instead
protected _validateId ( mixed $id ) : boolean
$id mixed
Résultat boolean

_viewAction() protected méthode

Triggers the following callbacks - Crud.init - Crud.beforeFind - Crud.recordNotFound - Crud.afterFind - Crud.beforeRender
protected _viewAction ( string $id = null ) : void
$id string
Résultat void

config() public méthode

If $key is an array and $value is empty, $key will be merged directly with $this->_config If $key is a string it will be passed into Hash::insert
public config ( mixed $key = null, mixed $value = null ) : TranslationsEvent
$key mixed
$value mixed
Résultat TranslationsEvent

disableAction() public méthode

Disable a CRUD action
public disableAction ( string $action ) : void
$action string The action to disable
Résultat void

enableAction() public méthode

Enable a CRUD action
public enableAction ( string $action ) : void
$action string The action to enable
Résultat void

executeAction() public méthode

Execute a Crud action
public executeAction ( string $controllerAction = null, $args = [] ) : mixed
$controllerAction string Override the controller action to execute as
Résultat mixed void, or a CakeResponse object

getIdFromRequest() public méthode

Helper method to get the passed ID to an action
public getIdFromRequest ( ) : string
Résultat string

getListener() public méthode

Get a single event class
public getListener ( string $name, $create = true ) : CrudBaseEvent
$name string
Résultat CrudBaseEvent

initialize() public méthode

The reason for this is that if we don't, the Auth component won't execute any callbacks on the controller like isAuthorized
public initialize ( Controller $controller ) : void
$controller Controller
Résultat void

isActionMapped() public méthode

Check if a CRUD action has been mapped (aka should be handled by CRUD component)
public isActionMapped ( string | null $action = null ) : boolean
$action string | null If null, use the current action
Résultat boolean

mapAction() public méthode

Map action to a internal request type
public mapAction ( string $action, string $type, boolean $enable = true ) : void
$action string The Controller action to fake
$type string one of the CRUD events (index, add, edit, delete, view)
$enable boolean Should the mapping be enabled right away?
Résultat void

mapActionView() public méthode

To map multiple action views in one go pass an array as first argument and no second argument
public mapActionView ( string | array $action, string $view = null ) : void
$action string | array
$view string
Résultat void

mapFindMethod() public méthode

Map a controller action to a Model::find($method)
public mapFindMethod ( string $action, strign $method ) : void
$action string
$method strign
Résultat void

on() public méthode

Attaches an event listener function to the controller for Crud Events
public on ( string | array $events, callback $callback ) : void
$events string | array Name of the Crud Event you want to attach to controller
$callback callback callable method or closure to be executed on event
Résultat void

trigger() public méthode

If Event listeners return a CakeResponse object, the this method will throw an exception and fill a 'response' property on it with a reference to the response object.
public trigger ( string $eventName, array $data = [] ) : CrudSubject
$eventName string
$data array
Résultat CrudSubject

Property Details

$_action protected_oe property

The current controller action
protected string $_action
Résultat string

$_controller protected_oe property

Reference to the current controller
protected Controller $_controller
Résultat Controller

$_eventManager protected_oe property

Reference to the current event manager
protected CakeEventManager $_eventManager
Résultat CakeEventManager

$_listeners protected_oe property

List of listener objects attached to Crud
protected array $_listeners
Résultat array

$_model protected_oe property

Cached property for the current Controller::modelClass instance
protected Model $_model
Résultat Model

$_modelName protected_oe property

Cached property for Controller::modelClass
protected string $_modelName
Résultat string

$_request protected_oe property

Reference to the current request
protected CakeRequest $_request
Résultat CakeRequest

$components public_oe property

Reference to a Session component
public array $components
Résultat array

$settings public_oe property

validateId ID Argument validation - by default it will inspect your model's primary key and based on it's data type either use integer or uuid validation. Can be disabled by setting it to "false". Supports "integer" and "uuid" configuration By default it's configuration is NULL, which means "auto detect" eventPrefix All emitted events will be prefixed with this property value secureDelete delete() can only be called with the HTTP DELETE verb, not POST when true. If set to false HTTP POST is also acceptable actions contains an array of controller methods this component should offer implementation for. The actions is used for actionMap, viewMap and findMethodMap to change behavior of CrudComponent By default no actions are enabled translations is the settings for the translations Event, responsible for the text used in flash messages see TranslationsEvent::$_defaults the full list of options relatedList is a map of the controller action and the whether it should fetch associations lists to be used in select boxes. An array as value means it is enabled and represent the list of model associations to be fetched saveAllOptions Raw array passed as 2nd argument to saveAll() in add and edit method If you configure a key with your action name, it will override the default settings. This is useful for adding fieldList to enhance security in saveAll. actionMap A map of the controller action and what CRUD action we should call. By default it supports non-prefix and admin_ prefixed routes viewMap A map of the controller action and the view to render By default it supports non-prefix and admin_ prefixed routes findMethodMap The default find method for reading data listenerClassMap List of internal-name => ${plugin}.${class} listeners that will be bound automatically in Crud. By default translations and related model events are bound. Events will always assume to be in the Controller/Event folder
public array $settings
Résultat array