问题
I have baked a plugin and added the \plugins\MyPlugin\src\View\Widget\BasicWidget.php
file:
namespace Cake\View\Widget;
use Cake\View\Widget\BasicWidget as BaseBasicWidget;
use Cake\View\Form\ContextInterface;
/**
* Basic input class.
*
* This input class can be used to render basic simple
* input elements like hidden, text, email, tel and other
* types.
*/
class BasicWidget implements BaseBasicWidget
{
public function render(array $data, ContextInterface $context)
{
$data += [
'name' => '',
'val' => null,
'type' => 'text',
'escape' => true,
'templateVars' => []
];
$data['value'] = $data['val'];
unset($data['val']);
return $this->_templates->format('input', [
'name' => $data['name'],
'type' => $data['type'],
'value' => $data['value'],
'templateVars' => $data['templateVars'],
'attrs' => $this->_templates->formatAttributes(
$data,
['name', 'type']
),
]);
}
}
The documentation here doesn't explain how to make this widget active: https://book.cakephp.org/3.0/en/views/helpers/form.html#adding-custom-widgets.
It suggests using $config['widgets']
like so:
$this->loadHelper('Form', [
'widgets' => [
'basic' => ['MyPlugin.Basic']
]
]);
but this ends up looking in the plugin's `\config' path with the following error:
Could not load configuration file: /Users/geoidesic/MyProject/config/Basic.php
来源:https://stackoverflow.com/questions/55679980/how-to-make-plugins-widget-override-the-default-cakephp-basicwidget