[英]How can I save staff_name column as others in CakePHP?
I am making ledger app to kill the paper work.我正在制作分类帐应用程序来杀死文书工作。
but making simple CRUD, there was a problem.但制作简单的 CRUD 时,出现了问题。
Other columns are OK, but one column cannot be saved.其他列都可以,但一列无法保存。
Would you take a look at this?你会看看这个吗?
I am just making add, edit, delete, and view ctp files as bake command generated.我只是在生成烘焙命令时添加、编辑、删除和查看 ctp 文件。
And the Controller also made by bake command.而 Controller 也是通过 bake 命令制作的。
I just changed POST method to GET method.我只是将 POST 方法更改为 GET 方法。
protected $_accessible = [
'*' => true
];
<div class="ledgers form large-9 medium-8 columns content">
<?= $this->Form->create($ledger) ?>
<fieldset>
<legend><?= __('Add Ledger') ?></legend>
<?php
$men = [
'Fukuda','Hayasi','Seki','Kubo'
];
$work_category = [
'preview','build','repair','etc'
];
echo $this->Form->control('customer_name');
echo $this->Form->control('customer_adress');
echo $this->Form->control('customer_tel1');
echo $this->Form->control('customer_tel2');
// need arr, $members = [hukuda, hayasi,ryo]
echo $this->Form->control('staff_name',
['options' => $men,
]);
echo $this->Form->control('work_category',
['options' => $work_category,
]);
echo $this->Form->control('content');
echo $this->Form->control('reserved');
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
I want to make select form to restrict categories.我想制作 select 表格来限制类别。
public function edit($id = null) {
// return the GET data (in url)
$ledger = $this->Ledgers->get($id);
// this is POST only -------------
if ($this->request->is(['patch', 'post', 'put'])) {
$ledger = $this->Ledgers->patchEntity(
$ledger, $this->request->getData());
if ($this->Ledgers->save($ledger)) {
$this->Flash->success(
__('The ledger has been saved.'));
return $this->redirect(
['action' => 'index']);
}
$this->Flash->error(
__('The ledger could not be saved.'));
}
// POST
$this->set(compact('ledger'));
}
MariaDB [fesa]> desc ledgers;
+-----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| customer_name | varchar(64) | NO | | NULL | |
| customer_adress | text | NO | | NULL | |
| customer_tel1 | varchar(64) | NO | | NULL | |
| customer_tel2 | varchar(64) | NO | | NULL | |
| work_category | varchar(255) | NO | | NULL | |
| content | text | NO | | NULL | |
| created | date | NO | | NULL | |
| reserved | date | NO | | NULL | |
| modified | date | NO | | NULL | |
| staff_name | varchar(64) | YES | | NULL | |
+-----------------+--------------+------+-----+---------+----------------+
11 rows in set (0.00 sec)
all code is here所有代码都在这里
https://github.com/kaede0902/cake3/tree/master/ledger/src https://github.com/kaede0902/cake3/tree/master/ledger/src
Table name was messed up.表名弄乱了。
I was confused because column staff_id
cannot use because of the cake php condition, So I made new column worker
and replacing this, but it was complicated.我很困惑,因为由于蛋糕 php 条件而无法使用列
staff_id
,所以我制作了新的列worker
并替换了它,但它很复杂。 It worked well when I integrate the code with staff_id
当我将代码与
staff_id
集成时效果很好
I was also confused by <th> and <td>
我也对
<th> and <td>
感到困惑
<th scope="col"><?= $this->Paginator->
sort('id') ?></th>
<th scope="col"><?= $this->Paginator->
sort('customer_name') ?></th>
<th scope="col"><?= $this->Paginator->
sort('customer_tel1') ?></th>
<th scope="col"><?= $this->Paginator->
sort('customer_tel2') ?></th>
<th scope="col"><?= $this->Paginator->
sort('staff_name') ?></th>
<th scope="col"><?= $this->Paginator->
sort('work_category') ?></th>
<th scope="col"><?= $this->Paginator->
sort('created') ?></th>
<th scope="col"><?= $this->Paginator->
sort('reserved') ?></th>
<th scope="col"><?= $this->Paginator->
sort('modified') ?></th>
<th scope="col" class="actions">
<?= __('Actions') ?></th>
<?php foreach ($ledgers as $ledger): ?>
<tr>
<td><?= $this->Number->format($ledger->id) ?></td>
<td><?= h($ledger->customer_name) ?></td>
<td><?= h($ledger->customer_tel1) ?></td>
<td><?= h($ledger->customer_tel2) ?></td>
<td><?= h($ledger->staff_name) ?></td>
<td><?= h($ledger->work_category) ?></td>
<td><?= h($ledger->created) ?></td>
<td><?= h($ledger->reserved) ?></td>
<td><?= h($ledger->modified) ?></td>
Try this select option may help.试试这个 select 选项可能会有所帮助。
add.ctp添加.ctp
<div class="ledgers form large-9 medium-8 columns content">
<?= $this->Form->create($ledger) ?>
<fieldset>
<legend><?= __('Add Ledger') ?></legend>
<?php
echo $this->Form->control('customer_name');
echo $this->Form->control('customer_adress');
echo $this->Form->control('customer_tel1');
echo $this->Form->control('customer_tel2');
echo $this->Form->control('staff_name', [
'type' => 'select',
'placeholder' => __('staff_name'),
'label' => __('staff_name'),
'empty' => __('(Choose Type)'),
'value' => $ledger->staff_name,
'options' => [
['value' => 'Fukuda', 'text' => __('Fukuda')],
['value' => 'Hayasi', 'text' => __('Hayasi')],
['value' => 'Seki', 'text' => __('Kubo')],
['value' => 'Kubo', 'text' => __('Kubo')]
]
]);
echo $this->Form->control('work_category ', [
'type' => 'select',
'placeholder' => __('work_category '),
'label' => __('work_category'),
'empty' => __('(Choose Type)'),
'value' => $ledger->work_category ,
'options' => [
['value' => 'preview', 'text' => __('preview')],
['value' => 'build', 'text' => __('build')],
['value' => 'repair', 'text' => __('repair')],
['value' => 'etc', 'text' => __('etc')]
]
]);
echo $this->Form->control('content');
echo $this->Form->control('reserved');
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
this style also help you for easy editing too.这种风格也可以帮助您轻松编辑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.