Как я могу сохранить столбец staff_name как другие в CakePHP? - PullRequest
1 голос
/ 03 октября 2019

Я делаю приложение главной книги, чтобы убить бумажную работу.

, но при создании простого CRUD возникла проблема.

Другие столбцы в порядке, но один столбец не может быть сохранен.

Не могли бы вы взглянуть на это?

Я просто делаю добавление, редактирование, удаление и просмотр файлов ctp в виде сгенерированной команды bake.

И контроллер тоже сделан по команде выпекания.

Я просто изменил метод POST на метод GET.

пробовал

  • переделывая столбцы таблицы, убедитесь, что я использую правильное имя.
  • убедитесь, что я использую правильную грамматику торта.
  • добавить доступ в Entity
    protected $_accessible = [
        '*' => true
    ];

add.ctp

<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>

Я хочу сделать форму выбора для ограничения категорий.

LedgersController.php

    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'));
    }

DB

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)

весь код здесь

https://github.com/kaede0902/cake3/tree/master/ledger/src

Ответы [ 2 ]

0 голосов
/ 04 октября 2019

Попробуйте этот вариант выбора может помочь.

add.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() ?>

Этот стиль также поможет вам легко редактировать.

0 голосов
/ 03 октября 2019

Имя таблицы испорчено.
Я был сбит с толку, потому что столбец staff_id не может использовать из-за условия php для торта, поэтому я создал новый столбец worker и заменил его, но это было сложно. Это работало хорошо, когда я интегрировал код с staff_id

Меня также смутило <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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...