如何在 Zend Framework 中将值从视图传递到控制器?
我知道,如果我将其放在链接上,然后点击该链接:
array('controller'=>'challenge','action'=>'evaluateChallenge','codTeam'=>$d["cod_challenge_team"]);
如果在控制器上我这样做:
$values = $this->_request->getParams();
$teamVo->setCodTeam($values['codTeam']);
我将获得所需的值。
我想做同样的事情,但是,没有用户交互。 每次我在视图侧循环槽值时,我打算将一个值传递给evaluateChallenge。
这是最愚蠢的问题之一,但它确实会带来损失。
我可以得到你的帮助吗?
或者至少告诉我我说错了什么。 :)
:::::::::::::::::::::::::::::::::::更新::::::::::: ::::::::::::::::::::::::::::::::::::
我想显示与给定团队相关的数据库记录元素列表。 这样我就可以拥有:
A队 - 鳕鱼队 - 挑战A - 参与者ABC - 积分 XXX
B队 - 鳕鱼队 - 挑战A - 参与者ABC - 积分 XXX
等等...
在我看来,代码翻译是这样的:
foreach ($challenge as $d) {
echo $d['challengeName'];
echo $d['participants'];
echo $d['points'];
}
一切都很好,很清晰。
现在,我需要向此列表添加其他信息,以便我可以得到如下内容:
A队 - 鳕鱼队 - 挑战A - 参与者ABC - 点数 XXX - FILESATTACHED_NEW_INFORMATION
B队 - 鳕鱼队 - 挑战A - 参与者ABC - 点数 XXX - FILESATTACHED_NEW_INFORMATION
等等...
这些新信息应该在视图助手上计算出来。好的。 我会弄清楚如何做到这一点。
然而,然后我需要在视图上调用该助手 - 对吗?在 foreach 所在的同一视图上。但是,我需要将 FilesAttached 与 foreach ($challenge as $d) 关联起来,对吗? - 或者还有其他办法吗?
如果没有其他办法: 我们如何将来自助手的数据与通过 foreach 视图中已存在的数据关联起来?
再次非常感谢, MEM
I know that, If I put this on a link, and I hit that link:
array('controller'=>'challenge','action'=>'evaluateChallenge','codTeam'=>$d["cod_challenge_team"]);
And if, on the controller I do:
$values = $this->_request->getParams();
$teamVo->setCodTeam($values['codTeam']);
that I will get the desired value.
I want to do the same, BUT, without the user to interact.
I intend to pass a value to evaluateChallenge, each time I loop trough values on the view side.
This is one of the most silly questions, but it sure translates the loss here.
Can I have your help?
Or at least tell me what I'm saying wrong. :)
::::::::::::::::::::::::::::::::::UPDATE::::::::::::::::::::::::::::::::::::::
I want to display a list of database records elements, related to a given team.
So that I can have:
TEAM A
- cod_team
- Challenge A
- Participants ABC
- Points XXXTEAM B
- cod_team
- Challenge A
- Participants ABC
- Points XXX
And so on...
The code translation to this on my view is something like this:
foreach ($challenge as $d) {
echo $d['challengeName'];
echo $d['participants'];
echo $d['points'];
}
All nice and clear.
Now, I need to add another information to this list so that I can have something like:
TEAM A
- cod_team
- Challenge A
- Participants ABC
- Points XXX
- FILESATTACHED_NEW_INFORMATIONTEAM B
- cod_team
- Challenge A
- Participants ABC
- Points XXX
- FILESATTACHED_NEW_INFORMATION
and so on...
This new information should be worked out on a view helper. Ok.
I will figure it out about how to do that.
Then, however, I need to call that helper on the view - correct? On that same view where the foreach is. However, I will need the FilesAttached to be associated with the foreach ($challenge as $d) somehow right? - Or is there other way around?
If there isn't another way around:
How can we relate the data coming from the helper, with the data already existent on the view via the foreach?
Thanks a lot again,
MEM
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 来做到这一点Action ViewHelper,但这会为每次调用创建一个新的调度循环。这将严重减慢您的应用程序的速度,即 为什么你应该避免它。 该助手也可能在 ZF2 中被删除。
更好的方法是使用您可以传入所需参数的 ViewHelper。然后,该视图助手将使用传递的参数查询适当的模型并返回您想要的值。只要这不会改变模型状态,它直接从View中获取数据就可以了。
RE 更新
这并没有什么魔力:
You could do that with the Action ViewHelper, but that would create a new dispatch loop for each call to it. This will severly slow down your application, which is why you should avoid it. The helper might also be removed in ZF2.
A better approach would be to use a ViewHelper that you can pass in the required arguments. That view helper will then query the appropiate model with the passed arguments and return the values you want. As long as this does not change the Model state, it is okay to fetch data from the View directly.
RE Update
There is no magic about it: