Fr3nch13/CakePHP Utilities

Cell
in package
implements EventDispatcherInterface uses EventDispatcherTrait, LocatorAwareTrait, ModelAwareTrait, ViewVarsTrait

AbstractYes

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

$_modelType

The model type to use.

protected string $_modelType = 'Table'

$_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 = []

$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
throws
Error

Include error details for PHP 7 fatal errors.

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
throws
MissingViewException

If view class was not found.

Return values
View

dispatchEvent()

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
EventInterface

fetchTable()

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
throws
CakeException

If $alias argument and $defaultTable property both are null.

see
TableLocator::get()
since
4.3.0
Return values
Table

getEventManager()

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
EventManagerInterface

getModelType()

Get the model type to be used by this class

public getModelType() : string
Return values
string

initialize()

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 like App\Model\Table\PostsTable::class.

$modelType : string|null = null

The type of repository to load. Defaults to the getModelType() value.

Tags
throws
MissingModelException

If the model class cannot be found.

throws
UnexpectedValueException

If $modelClass argument is not provided and ModelAwareTrait::$modelClass property value is empty.

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
throws
MissingCellTemplateException

When a MissingTemplateException is raised during rendering.

throws
BadMethodCallException
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
$this

setEventManager()

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
$this

setModelType()

Set the model type to be used by this class

public setModelType(string $modelType) : $this
Parameters
$modelType : string

The model type

Return values
$this

_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.


        
On this page

Search results