✓質問内容まとめ
・bakeした際に自動生成されるinput要素のカスタマイズ方法
・再度bakeすると上書きされてしまうので、データベース設計が完成してから
再度bakeして上書きはしないことは前提に各ページをカスタマイズが基本ですか?
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
Cakephpのバージョンは3です。
bakeした際に自動生成されるinput要素がデフォルトで全ての項目が
HTML
1<label for="username">項目名</label> 2<input type="text" name="カラム名" required="required" maxlength="12" id="カラム名">
となっています。
これを例えば登録画面でセレクトボックスやチェックボックスにしたい場合
以下のような感じで追記してあげれば良いのでしょうか?
PHP
1// コントローラ 2$this->set( 'select1', $this->Prefecture->find( 'list', array( 3 'fields' => array( 'id', 'prefecture') 4))); 5 6// ビュー 7echo $this->Form->input( 'prefecture', array( 8 'type' => 'select', 9 'options' => $select1 10// 'selected' => $selected // 規定値をvalueで指定 11// 'div' => false // div親要素の有無(true/false) 12// 'size' => 5 // 高さ設定(リストボックスとして表示) 13// 'empty' => true // 空白を許可 14));
※http://kwski.net/cakephp-2-x/1088/ より抜粋
また、その場合コントローラに追記する箇所は、こちらでしょうか?
PHP
1public function add() 2 { 3 $coordinator = $this->Coordinators->newEntity(); 4 if ($this->request->is('post')) { 5 $coordinator = $this->Coordinators->patchEntity($coordinator, $this->request->data); 6 if ($this->Coordinators->save($coordinator)) { 7 $this->Flash->success(__('The coordinator has been saved.')); 8 9 return $this->redirect(['action' => 'index']); 10 } else { 11 $this->Flash->error(__('The coordinator could not be saved. Please, try again.')); 12 } 13 } 14 $this->set(compact('coordinator')); 15 $this->set('_serialize', ['coordinator']); 16 }
再度bakeすると上書きされてしまうので、データベース設計が完成してから
各ページをカスタマイズが基本ですか?
Cakephp初学者です。
bakeばかりでこれからカスタマイズにしていければと考えています。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/15 06:38
2016/11/15 07:12
2016/11/15 07:21
2016/11/15 07:33
2016/11/15 07:47
2016/11/15 08:00
2016/11/15 08:14
2016/11/15 08:57
2016/11/15 13:16
2016/11/15 15:12
2016/11/15 15:28
2016/11/15 20:14
2016/11/16 01:28
2016/11/16 01:32
2016/11/16 01:35