Fields may be specified via the scaffold.fields configuration key. By
default, this will contain a list of all columns associated with the Table being
in scope. To limit the fields used, simply specify an array of fields.
$action = $this->Crud->action();
$action->setConfig('scaffold.fields', ['title', 'description']);
You may also specify an options array. For forms, CrudView makes use of the
FormHelper::inputs() method and will pass your array values as options when
generating the output.
$action = $this->Crud->action();
$action->setConfig('scaffold.fields', [
'title',
'thread_id' => [
'type' => 'text'
],
'featured' => [
'checked' => 'checked'
]
]);
If you wish to use the default automatic field population functionality but want
to specify settings for a few of the fields, you can use the
scaffold.field_settings configuration key:
$action = $this->Crud->action();
$action->setConfig('scaffold.field_settings', [
'title' => [
// options here
]
]);
You may also use the scaffold.fields_blacklist configuration key to remove
fields from the output if you are using the default automatic field population
functionality:
$action = $this->Crud->action();
$action->setConfig('scaffold.fields_blacklist', ['created', 'modified']);
You can group the form fields in tabs using the scaffold.form_tab_groups
configuration key:
$action = $this->Crud->action();
$action->setConfig('scaffold.form_tab_groups', [
'First Tab Header' => ['field_1', 'field_2'],
'Second Tab Header' => ['field_3', 'field_4'],
]);
If there are fields which are not listed under any group they will be
automatically shown under 1st tab with header Primary. You can customize
the primary group’s name using scaffold.form_primary_tab config.
$action = $this->Crud->action();
$action->setConfig('scaffold.form_primary_tab', 'Key Info');
By default, the Crud plugin will redirect all form submissions to the
controller’s index action. This can be changed by setting the
_redirect_url view variable:
$this->set('_redirect_url', ['action' => 'home']);
By default, closing the a form page in your browser will result in lost data.
However, you may force a user prompt by enabling dirty form checks using the
scaffold.form_enable_dirty_check configuration key:
$action = $this->Crud->action();
$action->setConfig('scaffold.form_enable_dirty_check', true);
The following custom view blocks are available for use within forms:
form.sidebar: Rendered on the side of a form. Will also change the form
width.
form.before_create: Rendered before FormHelper::create() is called.
form.after_create: Rendered after FormHelper::create() is called.
form.before_end: Rendered before FormHelper::end() is called.
form.after_end: Rendered after FormHelper::end() is called. Used by embedded Form::postLink() calls.
All the CrudView templates are built from several elements that can be
overridden by creating them in your own templates/element folder. The
following sections will list all the elements that can be overridden for each
type of action.
In general, if you want to override a template, it is a good idea to copy the
original implementation from
vendor/friendsofcake/crud-view/templates/element
Create templates/element/action-header.ctp to have full control over
what is displayed at the top of the page. This is shared across all page
types.
Create templates/element/form/buttons.ctp to change what is displayed
for form submission. You can expect the $formSubmitButtonText and
$formSubmitExtraButtons variables to be available