PHP Class Crud\Controller\Component\CrudComponent

Scaffolding on steroids! :) Licensed under The MIT License For full copyright and license information, please see the LICENSE.txt
Inheritance: extends Cake\Controller\Component
Afficher le fichier Open project: friendsofcake/crud Class Usage Examples

Protected Properties

Свойство Type Description
$_action string The current controller action.
$_actionInstances array List of crud actions.
$_controller Cake\Controller\Controller Reference to the current controller.
$_defaultConfig array eventPrefix All emitted events will be prefixed with this property value. actions contains an array of controller methods this component should offer implementation for. Each action maps to a CrudAction class. $controllerAction => $crudActionClass. Example: array('admin_index' => 'Crud.Index') By default no actions are enabled. listeners List of internal-name => ${plugin}.${class} listeners that will be bound automatically in Crud. By default the related model event are bound. Events will always assume to be in the Controller/Event folder. eventLogging boolean to determine whether the class should log triggered events.
$_eventLog array A flat array of the events triggered.
$_eventManager Cake\Event\EventManager Reference to the current event manager.
$_listenerInstances array List of listener objects attached to Crud.
$_modelName string Cached property for Controller::$modelClass. This is the model name of the current model.
$_request Cake\Network\Request Reference to the current request.

Méthodes publiques

Méthode Description
__construct ( Cake\Controller\ComponentRegistry $collection, array $config = [] ) Constructor
action ( string | null $name = null ) : BaseAction Get a CrudAction object by action name.
addListener ( string $name, string $className = null, array $config = [] ) : void Add a new listener to Crud
beforeFilter ( Cake\Event\Event $event ) : void Add self to list of components capable of dispatching an action.
controller ( ) : Controller Returns controller instance
defaults ( string $type, string | array $name, mixed $config = null ) : mixed Set or get defaults for listeners and actions.
disable ( string | array $actions ) : void Disable one or multiple CRUD actions.
enable ( string | array $actions ) : void Enable one or multiple CRUD actions.
entity ( array $data = [] ) : Cake\ORM\Entity Returns new entity
eventLog ( ) : array Returns an array of triggered events.
execute ( string $controllerAction = null, array $args = [] ) : Response Execute a Crud action
findMethod ( string | array $action, string | null $method = null ) : void Map a controller action to a Model::find($method).
getSubject ( array $additional = [] ) : Crud\Event\Subject Create a CakeEvent subject with the required properties.
isActionMapped ( string | null $action = null ) : boolean Check if a CRUD action has been mapped (whether it will be handled by CRUD component)
listener ( string $name ) : BaseListener Get a single event class.
logEvent ( string $eventName, array $data = [] ) : void Add a log entry for the event.
mapAction ( string $action, string | array $config = [], boolean $enable = true ) : void Map action to an internal request type.
normalizeArray ( array $array ) : array Normalize config array
on ( string | array $events, callback $callback, array $options = [] ) : void Attaches an event listener function to the controller for Crud Events.
removeListener ( string $name ) : boolean Remove a listener from Crud.
startup ( Cake\Event\Event $event ) : void Called after the Controller::beforeFilter() and before the controller action.
table ( ) : Table Returns controller's table instance.
trigger ( string $eventName, Crud\Event\Subject $data = null ) : Cake\Event\Event 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.
useModel ( string $modelName ) : void Sets the model class to be used during the action execution.
view ( string | array $action, string | null $view = null ) : void Map the view file to use for a controller action.
viewVar ( string | array $action, string | null $viewVar = null ) : void Change the viewVar name for one or multiple actions.

Méthodes protégées

Méthode Description
_loadAction ( string $name ) : BaseAction Load a CrudAction instance.
_loadListener ( string $name ) : BaseListener Load a single event class attached to Crud.
_loadListeners ( ) : void Load all event classes attached to Crud.

Method Details

__construct() public méthode

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

_loadAction() protected méthode

Load a CrudAction instance.
protected _loadAction ( string $name ) : BaseAction
$name string The controller action name.
Résultat Crud\Action\BaseAction

_loadListener() protected méthode

Load a single event class attached to Crud.
protected _loadListener ( string $name ) : BaseListener
$name string Name
Résultat Crud\Listener\BaseListener

_loadListeners() protected méthode

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

action() public méthode

Get a CrudAction object by action name.
public action ( string | null $name = null ) : BaseAction
$name string | null The controller action name.
Résultat Crud\Action\BaseAction

addListener() public méthode

This will not load or initialize the listener, only lazy-load it. If $name is provided but no $class argument, the className will be derived from the $name. CakePHP Plugin.ClassName format for $name and $class is supported.
public addListener ( string $name, string $className = null, array $config = [] ) : void
$name string Name
$className string Normal CakePHP plugin-dot annotation supported.
$config array Any default settings for a listener.
Résultat void

beforeFilter() public méthode

Add self to list of components capable of dispatching an action.
public beforeFilter ( Cake\Event\Event $event ) : void
$event Cake\Event\Event Event instance
Résultat void

controller() public méthode

Returns controller instance
public controller ( ) : Controller
Résultat Cake\Controller\Controller

defaults() public méthode

Set or get defaults for listeners and actions.
public defaults ( string $type, string | array $name, mixed $config = null ) : mixed
$type string Can be anything, but 'listeners' or 'actions' is currently only used.
$name string | array The name of the $type - e.g. 'api', 'relatedModels' or an array ('api', 'relatedModels'). If $name is an array, the $config will be applied to each entry in the $name array.
$config mixed If NULL, the defaults is returned, else the defaults are changed.
Résultat mixed

disable() public méthode

Disable one or multiple CRUD actions.
public disable ( string | array $actions ) : void
$actions string | array The action to disable.
Résultat void

enable() public méthode

Enable one or multiple CRUD actions.
public enable ( string | array $actions ) : void
$actions string | array The action to enable.
Résultat void

entity() public méthode

Returns new entity
public entity ( array $data = [] ) : Cake\ORM\Entity
$data array Data
Résultat Cake\ORM\Entity

eventLog() public méthode

Returns an array of triggered events.
public eventLog ( ) : array
Résultat array

execute() public méthode

Execute a Crud action
public execute ( string $controllerAction = null, array $args = [] ) : Response
$controllerAction string Override the controller action to execute as.
$args array List of arguments to pass to the CRUD action (Usually an ID to edit / delete).
Résultat Cake\Network\Response

findMethod() public méthode

To map multiple findMethods in one go pass an array as first argument and no second argument.
public findMethod ( string | array $action, string | null $method = null ) : void
$action string | array Action or array of actions.
$method string | null Find method name
Résultat void

getSubject() public méthode

Create a CakeEvent subject with the required properties.
public getSubject ( array $additional = [] ) : Crud\Event\Subject
$additional array Additional properties for the subject.
Résultat Crud\Event\Subject

isActionMapped() public méthode

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

listener() public méthode

Get a single event class.
public listener ( string $name ) : BaseListener
$name string Listener
Résultat Crud\Listener\BaseListener

logEvent() public méthode

Add a log entry for the event.
public logEvent ( string $eventName, array $data = [] ) : void
$eventName string Event name
$data array Event data
Résultat void

mapAction() public méthode

Map action to an internal request type.
public mapAction ( string $action, string | array $config = [], boolean $enable = true ) : void
$action string The Controller action to provide an implementation for.
$config string | array Config array or class name like Crud.Index.
$enable boolean Should the mapping be enabled right away?
Résultat void

normalizeArray() public méthode

Normalize config array
public normalizeArray ( array $array ) : array
$array array List to normalize
Résultat array

on() public méthode

Attaches an event listener function to the controller for Crud Events.
public on ( string | array $events, callback $callback, array $options = [] ) : 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.
$options array Used to set the `priority` and `passParams` flags to the listener.
Résultat void

removeListener() public méthode

This will also detach it from the EventManager if it's attached.
public removeListener ( string $name ) : boolean
$name string Name
Résultat boolean

startup() public méthode

Called after the Controller::beforeFilter() and before the controller action.
public startup ( Cake\Event\Event $event ) : void
$event Cake\Event\Event Event instance
Résultat void

table() public méthode

Returns controller's table instance.
public table ( ) : Table
Résultat Cake\ORM\Table

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, Crud\Event\Subject $data = null ) : Cake\Event\Event
$eventName string Event name
$data Crud\Event\Subject Event data
Résultat Cake\Event\Event

useModel() public méthode

Sets the model class to be used during the action execution.
public useModel ( string $modelName ) : void
$modelName string The name of the model to load.
Résultat void

view() public méthode

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

viewVar() public méthode

To map multiple action viewVars in one go pass an array as first argument and no second argument.
public viewVar ( string | array $action, string | null $viewVar = null ) : void
$action string | array Action or array of actions.
$viewVar string | null View var name.
Résultat void

Property Details

$_action protected_oe property

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

$_actionInstances protected_oe property

List of crud actions.
protected array $_actionInstances
Résultat array

$_controller protected_oe property

Reference to the current controller.
protected Controller,Cake\Controller $_controller
Résultat Cake\Controller\Controller

$_defaultConfig protected_oe property

eventPrefix All emitted events will be prefixed with this property value. actions contains an array of controller methods this component should offer implementation for. Each action maps to a CrudAction class. $controllerAction => $crudActionClass. Example: array('admin_index' => 'Crud.Index') By default no actions are enabled. listeners List of internal-name => ${plugin}.${class} listeners that will be bound automatically in Crud. By default the related model event are bound. Events will always assume to be in the Controller/Event folder. eventLogging boolean to determine whether the class should log triggered events.
protected array $_defaultConfig
Résultat array

$_eventLog protected_oe property

A flat array of the events triggered.
protected array $_eventLog
Résultat array

$_eventManager protected_oe property

Reference to the current event manager.
protected EventManager,Cake\Event $_eventManager
Résultat Cake\Event\EventManager

$_listenerInstances protected_oe property

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

$_modelName protected_oe property

Cached property for Controller::$modelClass. This is the model name of the current model.
protected string $_modelName
Résultat string

$_request protected_oe property

Reference to the current request.
protected Request,Cake\Network $_request
Résultat Cake\Network\Request