This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
/
form.ctp
65 lines (63 loc) · 2.08 KB
/
form.ctp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<%
use Cake\Utility\Inflector;
$fields = collection($fields)
->filter(function($field) use ($schema) {
return $schema->getColumnType($field) !== 'binary';
});
%>
<div class="<%= $pluralVar %> form">
<?= $this->Form->create($<%= $singularVar %>) ?>
<fieldset>
<legend><?= __('<%= Inflector::humanize($action) %> <%= $singularHumanName %>') ?></legend>
<?php
<%
foreach ($fields as $field) {
if (in_array($field, $primaryKey)) {
continue;
}
if (isset($keyFields[$field])) {
$fieldData = $schema->getColumn($field);
if (!empty($fieldData['null'])) {
%>
echo $this->Form->control('<%= $field %>', ['options' => $<%= $keyFields[$field] %>, 'empty' => true]);
<%
} else {
%>
echo $this->Form->control('<%= $field %>', ['options' => $<%= $keyFields[$field] %>]);
<%
}
continue;
}
if (!in_array($field, ['created', 'modified', 'updated'])) {
$fieldData = $schema->getColumn($field);
if (($fieldData['type'] === 'date') && (!empty($fieldData['null']))) {
%>
echo $this->Form->control('<%= $field %>', ['empty' => true, 'default' => '']);
<%
} else {
if (empty($fieldData['null'])) {
%>
echo $this->Form->control('<%= $field %>'); <% // Required fields %>
<%
} else {
%>
echo $this->Form->control('<%= $field %>');
<%
}
}
}
}
if (!empty($associations['BelongsToMany'])) {
foreach ($associations['BelongsToMany'] as $assocName => $assocData) {
%>
echo $this->Form->control('<%= $assocData['property'] %>._ids', ['options' => $<%= $assocData['variable'] %>]);
<%
}
}
%>
?>
</fieldset>
<?= $this->Form->button(__('Submit'), ['class' => 'btn btn-success']) ?>
<?= $this->Html->link('Cancel', ['action' => 'index'], ['class' => 'btn btn-default'])?>
<?= $this->Form->end() ?>
</div>