简体   繁体   English

如何在Zend Framework中将值从视图传递到控制器?

[英]How can I pass a value from view to controller in Zend Framework?

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:::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::: 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 XXX 小组A-cod_team-挑战A-参与者ABC-积分XXX

TEAM B - cod_team - Challenge A - Participants ABC - Points XXX 团队B-cod_team-挑战A-参与者ABC-积分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_INFORMATION 小组A-鳕鱼队-挑战A-参与者ABC-积分XXX- FILESATTACHED_NEW_INFORMATION

TEAM B - cod_team - Challenge A - Participants ABC - Points XXX - FILESATTACHED_NEW_INFORMATION 团队B-鳕鱼队-挑战A-参与者ABC-积分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. 在同一视图上,foreach在哪里。 However, I will need the FilesAttached to be associated with the foreach ($challenge as $d) somehow right? 但是,我将需要将FilesAttached与foreach($ challenge为$ d)相关联,对吗? - 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? 如果没有其他解决方法: 我们如何将来自帮助程序的数据与通过foreach在视图上已经存在的数据相关联?

Thanks a lot again, MEM 再次非常感谢,MEM

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. 我打算每次在视图侧循环谷值时都将一个值传递给评估挑战。

You could do that with the Action ViewHelper , but that would create a new dispatch loop for each call to it. 您可以使用Action ViewHelper做到这一点,但这将为每次调用创建一个新的调度循环。 This will severly slow down your application, which is why you should avoid it . 这将严重减慢您的应用程序的速度,这就是为什么应避免使用它的原因 The helper might also be removed in ZF2. 辅助程序也可能在ZF2中被删除。

A better approach would be to use a ViewHelper that you can pass in the required arguments. 更好的方法是使用可以传递必需参数的ViewHelper。 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 . 只要这不会更改Model状态, 就可以直接从View中获取数据

RE Update RE更新

There is no magic about it: 这没有魔术:

foreach ($challenge as $d) { 
    echo $d['challengeName'],
         $d['participants'],
         $d['points'];

    $results = $this->evaluateChallenge($d['cod_challenge_team']);
    // now do something with the results
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Zend框架使用render()时如何从视图和控制器中获取价值? - Zend framework how can i get value from view and controller when render() is used? 如何在不使用Zend Framework 2中的锚标记和表单的情况下将值从视图传递到控制器 - How to pass value from view to controller without using anchor tag and forms in Zend Framework 2 警告:从空值创建默认对象以将值从控制器传递到zend框架中的视图 - Warning: Creating default object from empty value to pass value from controller to view in zend framework Zend Framework 3在布局视图中将参数从控制器传递到视图帮助器 - Zend Framework 3 Pass Parameters from Controller to View Helper in Layout View 如何从控制器访问Zend Framework应用程序的配置? - How can I access the configuration of a Zend Framework application from a controller? Zend Framework-将参数从视图传递到控制器的安全方法 - Zend Framework - Secure way to pass parameter from view to controller 我如何从coutroller传递数据以在zend famwork中查看 - how i can pass data from coutroller to view in zend famwork 我可以渲染视图而不在zend Framework 2的动作控制器中返回它吗? - Can I render view without returning it in action controller in zend framework 2? 如何在zend框架中将错误从模型传递给控制器 - How to pass errors from model to controller in zend framework 将变量从Javascript传递到Zend框架控制器 - Pass variable from Javascript to Zend framework Controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM