Cell
in package
implements
EventDispatcherInterface
uses
EventDispatcherTrait, LocatorAwareTrait, ModelAwareTrait, ViewVarsTrait
Cell base.
Attributes
- #[AllowDynamicProperties]
Table of Contents
Interfaces
- EventDispatcherInterface
- Objects implementing this interface can emit events.
Constants
- TEMPLATE_FOLDER = 'cell'
- Constant for folder name containing cell templates.
Properties
- $_cache : array<string|int, mixed>|bool
- Caching setup.
- $_eventClass : string
- Default class name for new event objects.
- $_eventManager : EventManagerInterface|null
- Instance of the Cake\Event\EventManager this object is using to dispatch inner events.
- $_modelFactories : array<string|int, callable|LocatorInterface>
- A list of overridden model factory functions.
- $_modelType : string
- The model type to use.
- $_tableLocator : LocatorInterface|null
- Table locator instance
- $_validCellOptions : array<string|int, string>
- List of valid options (constructor's fourth arguments) Override this property in subclasses to allow which options you want set as properties in your Cell.
- $_viewBuilder : ViewBuilder|null
- The view builder instance being used.
- $action : string
- The cell's action to invoke.
- $args : array<string|int, mixed>
- Arguments to pass to cell's action.
- $defaultTable : string|null
- This object's default table alias.
- $modelClass : string|null
- This object's primary model class name. Should be a plural form.
- $request : ServerRequest
- An instance of a Cake\Http\ServerRequest object that contains information about the current request.
- $response : Response
- An instance of a Response object that contains information about the impending response
- $View : View
- Instance of the View created during rendering. Won't be set until after Cell::__toString()/render() is called.
Methods
- __construct() : mixed
- Constructor.
- __debugInfo() : array<string, mixed>
- Debug info.
- __toString() : string
- Magic method.
- createView() : View
- Constructs the view class instance based on the current configuration.
- dispatchEvent() : EventInterface
- Wrapper for creating and dispatching events.
- fetchTable() : Table
- Convenience method to get a table instance.
- getEventManager() : EventManagerInterface
- Returns the Cake\Event\EventManager manager instance for this object.
- getModelType() : string
- Get the model type to be used by this class
- getTableLocator() : LocatorInterface
- Gets the table locator.
- initialize() : void
- Initialization hook method.
- loadModel() : RepositoryInterface
- Loads and constructs repository objects required by this object
- modelFactory() : void
- Override a existing callable to generate repositories of a given type.
- render() : string
- Render the cell.
- set() : $this
- Saves a variable or an associative array of variables for use inside a template.
- setEventManager() : $this
- Returns the Cake\Event\EventManagerInterface instance for this object.
- setModelType() : $this
- Set the model type to be used by this class
- setTableLocator() : $this
- Sets the table locator.
- viewBuilder() : ViewBuilder
- Get the view builder being used.
- _cacheConfig() : array<string|int, mixed>
- Generate the cache key to use for this cell.
- _setModelClass() : void
- Set the modelClass property based on conventions.
Constants
TEMPLATE_FOLDER
Constant for folder name containing cell templates.
public
string
TEMPLATE_FOLDER
= 'cell'
Properties
$_cache
Caching setup.
protected
array<string|int, mixed>|bool
$_cache
= false
$_eventClass
Default class name for new event objects.
protected
string
$_eventClass
= \Cake\Event\Event::class
$_eventManager
Instance of the Cake\Event\EventManager this object is using to dispatch inner events.
protected
EventManagerInterface|null
$_eventManager
$_modelFactories
A list of overridden model factory functions.
protected
array<string|int, callable|LocatorInterface>
$_modelFactories
= []
$_modelType
The model type to use.
protected
string
$_modelType
= 'Table'
$_tableLocator
Table locator instance
protected
LocatorInterface|null
$_tableLocator
$_validCellOptions
List of valid options (constructor's fourth arguments) Override this property in subclasses to allow which options you want set as properties in your Cell.
protected
array<string|int, string>
$_validCellOptions
= []
$_viewBuilder
The view builder instance being used.
protected
ViewBuilder|null
$_viewBuilder
$action
The cell's action to invoke.
protected
string
$action
$args
Arguments to pass to cell's action.
protected
array<string|int, mixed>
$args
= []
$defaultTable
This object's default table alias.
protected
string|null
$defaultTable
= null
$modelClass
This object's primary model class name. Should be a plural form.
Use Cake\ORM\Locator\LocatorAwareTrait::$defaultTable
instead.
protected
string|null
$modelClass
CakePHP will not inflect the name.
Example: For an object named 'Comments', the modelClass would be 'Comments'.
Plugin classes should use Plugin.Comments
style names to correctly load
models from the correct plugin.
Use empty string to not use auto-loading on this object. Null auto-detects based on controller name.
$request
An instance of a Cake\Http\ServerRequest object that contains information about the current request.
protected
ServerRequest
$request
This object contains all the information about a request and several methods for reading additional information about the request.
$response
An instance of a Response object that contains information about the impending response
protected
Response
$response
$View
Instance of the View created during rendering. Won't be set until after Cell::__toString()/render() is called.
protected
View
$View
Methods
__construct()
Constructor.
public
__construct(ServerRequest $request, Response $response[, EventManagerInterface|null $eventManager = null ][, array<string, mixed> $cellOptions = [] ]) : mixed
Parameters
- $request : ServerRequest
-
The request to use in the cell.
- $response : Response
-
The response to use in the cell.
- $eventManager : EventManagerInterface|null = null
-
The eventManager to bind events to.
- $cellOptions : array<string, mixed> = []
-
Cell options to apply.
__debugInfo()
Debug info.
public
__debugInfo() : array<string, mixed>
Return values
array<string, mixed>__toString()
Magic method.
public
__toString() : string
Starts the rendering process when Cell is echoed.
Note This method will trigger an error when view rendering has a problem. This is because PHP will not allow a __toString() method to throw an exception.
Tags
Return values
string —Rendered cell
createView()
Constructs the view class instance based on the current configuration.
public
createView([string|null $viewClass = null ]) : View
Parameters
- $viewClass : string|null = null
-
Optional namespaced class name of the View class to instantiate.
Tags
Return values
ViewdispatchEvent()
Wrapper for creating and dispatching events.
public
dispatchEvent(string $name[, array<string|int, mixed>|null $data = null ][, object|null $subject = null ]) : EventInterface
Returns a dispatched event.
Parameters
- $name : string
-
Name of the event.
- $data : array<string|int, mixed>|null = null
-
Any value you wish to be transported with this event to it can be read by listeners.
- $subject : object|null = null
-
The object that this event applies to ($this by default).
Return values
EventInterfacefetchTable()
Convenience method to get a table instance.
public
fetchTable([string|null $alias = null ][, array<string, mixed> $options = [] ]) : Table
Parameters
- $alias : string|null = null
-
The alias name you want to get. Should be in CamelCase format. If
null
then the value of $defaultTable property is used. - $options : array<string, mixed> = []
-
The options you want to build the table with. If a table has already been loaded the registry options will be ignored.
Tags
Return values
TablegetEventManager()
Returns the Cake\Event\EventManager manager instance for this object.
public
getEventManager() : EventManagerInterface
You can use this instance to register any new listeners or callbacks to the object events, or create your own events and trigger them at will.
Return values
EventManagerInterfacegetModelType()
Get the model type to be used by this class
public
getModelType() : string
Return values
stringgetTableLocator()
Gets the table locator.
public
getTableLocator() : LocatorInterface
Return values
LocatorInterfaceinitialize()
Initialization hook method.
public
initialize() : void
Implement this method to avoid having to overwrite the constructor and calling parent::__construct().
loadModel()
Loads and constructs repository objects required by this object
public
loadModel([string|null $modelClass = null ][, string|null $modelType = null ]) : RepositoryInterface
Use LocatorAwareTrait::fetchTable()
instead.
Typically used to load ORM Table objects as required. Can also be used to load other types of repository objects your application uses.
If a repository provider does not return an object a MissingModelException will be thrown.
Parameters
- $modelClass : string|null = null
-
Name of model class to load. Defaults to $this->modelClass. The name can be an alias like
'Post'
or FQCN likeApp\Model\Table\PostsTable::class
. - $modelType : string|null = null
-
The type of repository to load. Defaults to the getModelType() value.
Tags
Return values
RepositoryInterface —The model instance created.
modelFactory()
Override a existing callable to generate repositories of a given type.
public
modelFactory(string $type, LocatorInterface|callable $factory) : void
Parameters
- $type : string
-
The name of the repository type the factory function is for.
- $factory : LocatorInterface|callable
-
The factory function used to create instances.
render()
Render the cell.
public
render([string|null $template = null ]) : string
Parameters
- $template : string|null = null
-
Custom template name to render. If not provided (null), the last value will be used. This value is automatically set by
CellTrait::cell()
.
Tags
Return values
string —The rendered cell.
set()
Saves a variable or an associative array of variables for use inside a template.
public
set(array<string|int, mixed>|string $name[, mixed $value = null ]) : $this
Parameters
- $name : array<string|int, mixed>|string
-
A string or an array of data.
- $value : mixed = null
-
Value in case $name is a string (which then works as the key). Unused if $name is an associative array, otherwise serves as the values to $name's keys.
Return values
$thissetEventManager()
Returns the Cake\Event\EventManagerInterface instance for this object.
public
setEventManager(EventManagerInterface $eventManager) : $this
You can use this instance to register any new listeners or callbacks to the object events, or create your own events and trigger them at will.
Parameters
- $eventManager : EventManagerInterface
-
the eventManager to set
Return values
$thissetModelType()
Set the model type to be used by this class
public
setModelType(string $modelType) : $this
Parameters
- $modelType : string
-
The model type
Return values
$thissetTableLocator()
Sets the table locator.
public
setTableLocator(LocatorInterface $tableLocator) : $this
Parameters
- $tableLocator : LocatorInterface
-
LocatorInterface instance.
Return values
$thisviewBuilder()
Get the view builder being used.
public
viewBuilder() : ViewBuilder
Return values
ViewBuilder_cacheConfig()
Generate the cache key to use for this cell.
protected
_cacheConfig(string $action[, string|null $template = null ]) : array<string|int, mixed>
If the key is undefined, the cell class and action name will be used.
Parameters
- $action : string
-
The action invoked.
- $template : string|null = null
-
The name of the template to be rendered.
Return values
array<string|int, mixed> —The cache configuration.
_setModelClass()
Set the modelClass property based on conventions.
protected
_setModelClass(string $name) : void
If the property is already set it will not be overwritten
Parameters
- $name : string
-
Class name.