如何在 Zend Framework 中将变量从视图传递到控制器操作
有这行代码
<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());
}
}
我有这个操作如何在我的操作(calllogsAction
)中获取我的视图变量($record->phone_service_id;
)代码>)? 我没有提交,这只是一个链接。我想我不能在我的行动 calllogsAction 中这样做
$request = $this->getRequest();
$phone_service_id = $request->getParam("id");
In my view i have this line of code
<a href="<?php echo $this->url.'/login/calllogs/id/'.$record->phone_service_id;?>">Control Panel</a>
in my Login Controller I have this action
public function calllogsAction(){
if(!Zend_Auth::getInstance()->hasIdentity()){
$this->_redirect('login/login');
} else{
$request = $this->getRequest();
$this->view->assign('url', $request->getBaseURL());
}
}
How can i get my view variable ($record->phone_service_id;
) in my action (calllogsAction
)?
I am not submitting , this is just a link. I think i cant do it it like this in my action calllogsAction
$request = $this->getRequest();
$phone_service_id = $request->getParam("id");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您不希望 id 显示在地址栏中,则必须使用 POST。 使用
在表单内
而不是普通链接:并在控制器中使用
If you don't want the id to show in the address bar, then you will have to use POST. Use
instead of a plain link, inside the form:
and in the controller use
事实证明,最初的答案与您的尝试相同。
如果您不想在地址栏中显示 id(请记住,如果有合适的工具,任何人都可以看到发布数据),那么您的另一个选择是使用带有表单的 POST -
然后您需要使用 getPost 而不是控制器中的 getParam 来获取变量。
Initial answer was the same as your attempt, as it turns out.
If you don't want the id in the address bar (bear in mind anyone can see post data if they have the right tools anyway) then your other option is using POST with a form -
You'd then need to use getPost rather than getParam in the controller to get the variable.