如何在Zend Framework中从View To Controller Action传递变量

时间:2012-01-31 09:38:31

标签: zend-framework zend-view zend-controller

在我看来,我有这行代码

<a href="<?php echo $this->url.'/login/calllogs/id/'.$record->phone_service_id;?>">Control Panel</a>

在我的登录控制器中我有这个动作

public function calllogsAction(){
    if(!Zend_Auth::getInstance()->hasIdentity()){
        $this->_redirect('login/login');
    } else{
        $request = $this->getRequest();
        $this->view->assign('url', $request->getBaseURL());
    }
}

如何在我的操作($record->phone_service_id;)中获取我的视图变量(calllogsAction)? 我不提交,这只是一个链接。我想在我的动作calllogsAction

中我不能这样做
$request = $this->getRequest();
$phone_service_id =  $request->getParam("id");

2 个答案:

答案 0 :(得分:1)

事实证明,初步答案与您的尝试相同。

如果你不想在地址栏中输入id(请记住,如果他们有合适的工具,任何人都可以查看帖子数据),那么你的另一个选择就是使用带有表格的POST -

<form action="<?php echo $this->url.'/login/calllogs/id';?>" method="post">
<input type="hidden" name="id" value="<?php echo $record->phone_service_id; ?>" />
<input type="submit" name="submit" value="Control Panel" />
</form>

然后你需要在控制器中使用getPost而不是getParam来获取变量。

答案 1 :(得分:1)

如果您不希望ID显示在地址栏中,则必须使用POST。使用

<form method="post" action="<?php /*your URL here*/ ?>">

而不是普通链接,在表单内:

<input type="hidden" name="id" value="<?php /*your id here*/ ?>"/>

并在控制器中使用

$id = $this->getRequest()->getPost("id");