public method

Allows you to configure a default set of options which are included on a per-method basis, and configure method template overrides.

To force all <label /> elements to have a default class attribute value of "foo", simply do the following:

$this->form->config(['label' => ['class' => 'foo']]);

Note that this can be overridden on a case-by-case basis, and when overriding, values are not merged or combined. Therefore, if you wanted a particular <label /> to have both foo and bar as classes, you would have to specify 'class' => 'foo bar'.

You can also use this method to change the string template that a method uses to render its content. For example, the default template for rendering a checkbox is '<input type="checkbox" name="{:name}"{:options} />'. However, suppose you implemented your own custom UI elements, and you wanted to change the markup used, you could do the following:

$this->form->config(['templates' => [
	'checkbox' => '<div id="{:name}" class="ui-checkbox-element"{:options}></div>'

Now, for any calls to $this->form->checkbox(), your custom markup template will be applied. This works for any Form method that renders HTML elements.


  • array $config

    An associative array where the keys are Form method names (or 'templates', to include a template-overriding sub-array), and the values are arrays of configuration options to be included in the $options parameter of each method specified.



Returns an array containing the currently set per-method configurations, and an array of the currently set template overrides (in the 'templates' array key).


	public function config(array $config = []) {
		if (!$config) {
			$keys = ['base' => '', 'text' => '', 'textarea' => '', 'attributes' => ''];
			return ['templates' => $this->_templateMap] + array_intersect_key(
				$this->_config, $keys
		if (isset($config['templates'])) {
			$this->_templateMap = $config['templates'] + $this->_templateMap;
		return ($this->_config = Set::merge($this->_config, $config)) + [
			'templates' => $this->_templateMap