简体   繁体   中英

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::::::::::::::::::::::::::::::::::::::

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

TEAM 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_INFORMATION

TEAM 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

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. 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:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM