0

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

MEM
  • 30,529
  • 42
  • 121
  • 191

1 Answers1

1

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
}
Community
  • 1
  • 1
Gordon
  • 312,688
  • 75
  • 539
  • 559
  • Thanks a lot Gordon, you totally hit my doubts here. I'm not yet seeing however, how can I relate that view with the already existent loop on the view. I mean, on that view I have something like: foreach $challenge as $c echo $c['name'], echo $c['points'], etc... and within that loop I would like to add something. You are telling me that THAT something should be created on a helper, ok. This may sound silly but: How can I relate that helper call so that, what is returned by the helper is synchronized with the view loop interation on a given point. I'm getting lost again, I can remake this.. – MEM Jan 30 '11 at 23:47
  • @MEM sorry, I don't understand. Can you update your question with a code example and explain what is meant by "synchronized with the view loop interaction". – Gordon Jan 31 '11 at 08:25
  • @Gordon: I will update my question surely. Thanks a lot for your time here. I'm in the middle of something but, once finished I update my question, and let you know by comment. hks a lot. :) – MEM Jan 31 '11 at 10:42
  • @Gordon My question has been updated. If more information is required I will be able to provide it of course. The question is long but fairly simple, I'm not a php guru, unfortunately. I'm learning on a very basic level and that should be taken into consideration. :) – MEM Jan 31 '11 at 16:53
  • @MEM not sure if this what you are looking for, but updated the answer – Gordon Jan 31 '11 at 17:04
  • @Gordon I knew it was simple. 1) - evaluateChallenge is the helper name yes? 2) Wouldn't that be, as well, a big application hit? I mean, foreach record, the application will go to the helper, the helper will communicate with the DAO the dao with the database, the database return the data, pass it to the DAO and back to the helper, and finally to the view? - Well this is NOT a big application anyway, but I just want to make sure I get it right. :) – MEM Jan 31 '11 at 17:16
  • 1
    @MEM 1) yes, that's the helper method. How to write custom helpers is documented in the ZF Reference Guide. 2) Yes, but it would still be less impact than going through dispatch again, which means full bootstrap and routing and roundtrip to DB and everything else. Is there any chance you could fetch that additional data with a JOIN when fetching the initial data in the controller? – Gordon Jan 31 '11 at 17:21
  • @Gordon I don't know you but you sure are a brilliant preceptor. You totally get my doubts. :) 1) I will have a look to ZF Reference Guide. 2) I will try to read more about dispatch, so that I understand what dispatch means. 2.1) That is indeed a preferable method and I will try that one first. Then, try the helper. Thanks A LOT. :) – MEM Jan 31 '11 at 17:29
  • @MEM thanks and you're welcome. For the Dispatch, see http://devzone.zend.com/article/11978 – Gordon Jan 31 '11 at 17:35