【CakePHP3】一覧表示したもののうちの一つを次のページで表示したい
CakePHPでTodoアプリを作成しております。
indexページに一覧が出るようにしており、一覧のタイトルをリンクにしています。
これを押下することでviewページに飛んでその内容を表示させたいです。
ところがviewに飛んだ時にDBの値を表示できません。
var_dumpやechoで変数にDBの値が入っていることは確認できてます。
index
ctp
1<!--index.ctp--> 2<h1>Todoリスト</h1> 3 <?= $this->Html->link('新規追加', ['action' => 'new_task']) ?> 4 5 <table> 6 <th>タスク名</th> 7 <th>詳細</th> 8 <th>担当者</th> 9 <th>状態</th> 10 <th>登録日</th> 11 <th>更新日</th> 12 13 <?php foreach ($tasks as $task): ?> 14 <tr> 15 <td><?= $this->Html->link($task->task_name, ['action' => 'view', $task->task_id]) ?></td> 16 <td><?= h($task->task_detail); ?></td> 17 <td><?= h($task->fk_user_id); ?></td> 18 <td><?= h($task->fk_status_id); ?></td> 19 <td><?= h($task->create_date); ?></td> 20 <td><?= h($task->update_date); ?></td> 21 22 </tr> 23 <?php endforeach; ?> 24 </table>
php
1//TodoController.php 2 public function index() { 3 $tasks = $this->Tasks->find()->where(['del_flg' => '0']); 4 $this->set(compact('tasks')); 5 }
リンク押下で
http://localhost:8888/to-do-app/todo/view/1
に遷移します。
view
ctp
1<!--view.ctp--> 2 <p><?= h($task->task_name); ?></p> 3<!--とりあえずこれだけ-->
php
1//TodoController 2 public function view($task_id = null){ 3 $task = $this->Tasks->find() 4 ->where(['task_id' => $task_id, 'del_flg' => '0']) 5 ->firstOrFail(); 6 $this->set('tasks', $task); 7 }
試したこと
var_dump($task);
をしたらDBから変数に値が格納されていることを確認できました。
CakePHPには初めて触れるのでわかるかたいらっしゃったらよろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/08 11:37