11.07 php saved
Paul_Herron
Tags add more
array element rewrit  
Note
After fetching articles from the database, I want to use a function called chopText on each "body" field. chopText expects to be passed a variable to chop and a number of characters to chop it down to.

The setup works fine for standard variables, but I can't work out how to update an array element. I figured setting up a foreach loop like this would work, but the articles array remains unaffected in the view. Any ideas?
  1. $articles = $this->Article->findAll();
  2.  foreach ($articles as $article):
  3.     $article["Article"]["body"] = $this->chopText($article["Article"]["body"], 20);
  4.  endforeach;       
  5.  $this->set('articles', $articles);
Parsed in 0.015 seconds, using GeSHi 1.0.7.14

Modify this Paste