PHP Класс 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.
См. также: http://book.cakephp.org/2.0/en/controllers/components.html#Component
Наследование: extends Component
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$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)

Свойство Тип Описание
$_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

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
_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

Описание методов

__construct() публичный Метод

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() защищенный Метод

Triggers the following callbacks - Crud.init - Crud.beforeSave - Crud.afterSave - Crud.beforeRender
protected _addAction ( ) : void
Результат void

_deleteAction() защищенный Метод

Triggers the following callbacks - beforeFind - recordNotFound - beforeDelete - afterDelete
protected _deleteAction ( string $id = null ) : void
$id string
Результат void

_detectPrimaryKeyFieldType() защищенный Метод

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
Результат string

_editAction() защищенный Метод

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
Результат void

_getFindMethod() защищенный Метод

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
Результат string The find method used in ->_model->find($method)

_getResourceName() защищенный Метод

By default it uses Inflector::humanize, but can be changed using the "name" configuration property
protected _getResourceName ( ) : string
Результат string

_getSaveAllOptions() защищенный Метод

Merges defaults + any custom options for the specific action
protected _getSaveAllOptions ( string | null $action = null ) : array
$action string | null
Результат array

_getSubject() защищенный Метод

Create a CakeEvent subject with the required properties
protected _getSubject ( array $additional = [] ) : CrudSubject
$additional array Additional properties for the subject
Результат CrudSubject

_indexAction() защищенный Метод

Triggers the following callbacks - Crud.init - Crud.beforePaginate - Crud.afterPaginate - Crud.beforeRender
protected _indexAction ( ) : void
Результат void

_loadListener() защищенный Метод

Load a single event class attached to Crud
protected _loadListener ( string $name ) : void
$name string
Результат void

_loadListeners() защищенный Метод

Load all event classes attached to Crud
protected _loadListeners ( ) : void
Результат void

_redirect() защищенный Метод

Called for all redirects inside CRUD
protected _redirect ( CrudSubject $subject, array | null $url = null ) : void
$subject CrudSubject
$url array | null
Результат void

_setFlash() защищенный Метод

Wrapper for Session::setFlash
protected _setFlash ( string $type ) : void
$type string Message type
Результат void

_setModelProperties() защищенный Метод

Set internal model properties from the controller
protected _setModelProperties ( ) : void
Результат void

_validateId() защищенный Метод

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
Результат boolean

_viewAction() защищенный Метод

Triggers the following callbacks - Crud.init - Crud.beforeFind - Crud.recordNotFound - Crud.afterFind - Crud.beforeRender
protected _viewAction ( string $id = null ) : void
$id string
Результат void

config() публичный Метод

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
Результат TranslationsEvent

disableAction() публичный Метод

Disable a CRUD action
public disableAction ( string $action ) : void
$action string The action to disable
Результат void

enableAction() публичный Метод

Enable a CRUD action
public enableAction ( string $action ) : void
$action string The action to enable
Результат void

executeAction() публичный Метод

Execute a Crud action
public executeAction ( string $controllerAction = null, $args = [] ) : mixed
$controllerAction string Override the controller action to execute as
Результат mixed void, or a CakeResponse object

getIdFromRequest() публичный Метод

Helper method to get the passed ID to an action
public getIdFromRequest ( ) : string
Результат string

getListener() публичный Метод

Get a single event class
public getListener ( string $name, $create = true ) : CrudBaseEvent
$name string
Результат CrudBaseEvent

initialize() публичный Метод

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
Результат void

isActionMapped() публичный Метод

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
Результат boolean

mapAction() публичный Метод

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?
Результат void

mapActionView() публичный Метод

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
Результат void

mapFindMethod() публичный Метод

Map a controller action to a Model::find($method)
public mapFindMethod ( string $action, strign $method ) : void
$action string
$method strign
Результат void

on() публичный Метод

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
Результат void

trigger() публичный Метод

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
Результат CrudSubject

Описание свойств

$_action защищенное свойство

The current controller action
protected string $_action
Результат string

$_controller защищенное свойство

Reference to the current controller
protected Controller $_controller
Результат Controller

$_eventManager защищенное свойство

Reference to the current event manager
protected CakeEventManager $_eventManager
Результат CakeEventManager

$_listeners защищенное свойство

List of listener objects attached to Crud
protected array $_listeners
Результат array

$_model защищенное свойство

Cached property for the current Controller::modelClass instance
protected Model $_model
Результат Model

$_modelName защищенное свойство

Cached property for Controller::modelClass
protected string $_modelName
Результат string

$_request защищенное свойство

Reference to the current request
protected CakeRequest $_request
Результат CakeRequest

$components публичное свойство

Reference to a Session component
public array $components
Результат array

$settings публичное свойство

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
Результат array