CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 4.6 Strawberry API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 4.6
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget

Class WidgetLocator

A registry/factory for input widgets.

Can be used by helpers/view logic to build form widgets and other HTML widgets.

This class handles the mapping between names and concrete classes. It also has a basic name based dependency resolver that allows widgets to depend on each other.

Each widget should expect a StringTemplate instance as their first argument. All other dependencies will be included after.

Widgets can ask for the current view by using the _view widget.

Namespace: Cake\View\Widget

Property Summary

  • $_templates protected
    Cake\View\StringTemplate

    Templates to use.

  • $_view protected
    Cake\View\View

    View instance.

  • $_widgets protected
    array

    Array of widgets + widget configuration.

Method Summary

  • __construct() public

    Constructor

  • _resolveWidget() protected

    Resolves a widget spec into an instance.

  • add() public

    Adds or replaces existing widget instances/configuration with new ones.

  • clear() public

    Clear the registry and reset the widgets.

  • get() public

    Get a widget.

  • load() public

    Load a config file containing widgets.

Method Detail

__construct() ¶ public

__construct(Cake\View\StringTemplate $templates, Cake\View\View $view, array $widgets = [])

Constructor

Parameters
Cake\View\StringTemplate $templates

Templates instance to use.

Cake\View\View $view

The view instance to set as a widget.

array $widgets optional

See add() method for more information.

_resolveWidget() ¶ protected

_resolveWidget(mixed $config): Cake\View\Widget\WidgetInterface

Resolves a widget spec into an instance.

Parameters
mixed $config

The widget config.

Returns
Cake\View\Widget\WidgetInterface
Throws
ReflectionException

add() ¶ public

add(array $widgets): void

Adds or replaces existing widget instances/configuration with new ones.

Widget arrays can either be descriptions or instances. For example:

$registry->add([
  'label' => new MyLabelWidget($templates),
  'checkbox' => ['Fancy.MyCheckbox', 'label']
]);

The above shows how to define widgets as instances or as descriptions including dependencies. Classes can be defined with plugin notation, or fully namespaced class names.

Parameters
array $widgets

Array of widgets to use.

Returns
void
Throws
RuntimeException
When class does not implement WidgetInterface.

clear() ¶ public

clear(): void

Clear the registry and reset the widgets.

Returns
void

get() ¶ public

get(string $name): Cake\View\Widget\WidgetInterface

Get a widget.

Will either fetch an already created widget, or create a new instance if the widget has been defined. If the widget is undefined an instance of the _default widget will be returned. An exception will be thrown if the _default widget is undefined.

Parameters
string $name

The widget name to get.

Returns
Cake\View\Widget\WidgetInterface
Throws
RuntimeException
when widget is undefined.

load() ¶ public

load(string $file): void

Load a config file containing widgets.

Widget files should define a $config variable containing all the widgets to load. Loaded widgets will be merged with existing widgets.

Parameters
string $file

The file to load

Returns
void

Property Detail

$_templates ¶ protected

Templates to use.

Type
Cake\View\StringTemplate

$_view ¶ protected

View instance.

Type
Cake\View\View

$_widgets ¶ protected

Array of widgets + widget configuration.

Type
array
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs