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
파일 보기 프로젝트 열기: nodesagency/Platform-Crud-Plugin 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$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

보호된 프로퍼티들

프로퍼티 타입 설명
$_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