ZF2.In でビュー ファイルを作成し、コントローラーに ID を渡します。
コントローラーでこのIDを取得するにはどうすればよいですか?
IDを取得したいshowActionコードは次のとおりです。
public function showAction()
{
$id = (int) $this->params()->fromRoute('id', 0);
if (!$id) {
return $this->redirect()->toRoute('calendar', array(
'action' => 'create'
));
}
}
そして、これがコントローラーを表示するためにidを渡す私のindex.phtmlです:
<table class="table">
<tr>
<th>Calendar name</th>
<th>Description</th>
<th>Actions</th>
</tr>
<?php foreach ($calendars as $key => $value) : ?>
<tr>
<td>
<a href="<?php echo $this->url('calendar',array('action'=>'show', 'id' => $this->escapeHtml($value['_id'])));?>">
<?php echo $this->escapeHtml($value['title']);?>
</a>
</td>
<td><?php echo $this->escapeHtml($value['description']);?></td>
<td>
<a href="<?php echo $this->url('calendar',
array('action'=>'settings', 'id' => $this->escapeHtml($value['_id'])));?>">Settings</a>
<a href="<?php echo $this->url('calendar',
array('action'=>'delete', 'id' => $this->escapeHtml($value['_id'])));?>">delete</a>
</td>
</tr>
<?php endforeach; ?>
</table>