2009年3月17日星期二

Re: [fw-mvc] passing viewpage id var to controller?

Kevin Nelson wrote:
> viewpage.phtml
>
> <a href="<?php echo $this->baseUrl; ?>/contacts/edit/id/<?php echo
> $this->entry['id']; ?>">Edit</a>
>
> ----------------------------
> MyController extends Zend_Controller_Action
>
> public function detailsAction()
> {
> $model = $this->_getModel();
>
> $this->view->entry= $model->fetchEntry();
> // How do I get the id into fetchEntry()? EG:
> $this->view->entry= $model->fetchEntry($id);
> }
> ----------------------------

Hi Kevin,

You'd want to use the _getParam() method in your controller, such as:

$this->view->entry= $model->fetchEntry($this->_getParam('id'));

By default, if the parameter is not found (in this case 'id') the
_getParam method will return null, but you can default it to something
else by passing a second parameter, such as:

$this->_getParam('id', 1)

Andy

没有评论: