11.07
php
saved
Paul_Herron
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?
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?
- $articles = $this->Article->findAll();
- foreach ($articles as $article):
- $article["Article"]["body"] = $this->chopText($article["Article"]["body"], 20);
- endforeach;
- $this->set('articles', $articles);
Parsed in 0.015 seconds, using GeSHi 1.0.7.14