我在 ZF2 中创建了一个视图文件。在其中我将 id 传递给控制器。
我如何在控制器中获取此 ID?
这是我想要获取 id 的 showAction 代码:
public function showAction()
{
$id = (int) $this->params()->fromRoute('id', 0);
if (!$id) {
return $this->redirect()->toRoute('calendar', array(
'action' => 'create'
));
}
}
这是我的 index.phtml,我将 id 传递给显示控制器:
<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>