0

I have a normal foreach call foreach($users as $k=>$user): in my view.

However in this loop i need to call a function from either my controller or model (not sure where), that goes and runs a few other web based checks and returns an array as a result...

How do i call a function from within my foreach loop inside my view? Or is there another way i am unaware of?

medoix
  • 1,189
  • 2
  • 16
  • 36
  • 1
    Possible duplicate of [Can I call a Model from a View?](http://stackoverflow.com/questions/1973221/can-i-call-a-model-from-a-view) and [many similar questions](http://stackoverflow.com/search?q=cakephp+call+model+from+view&submit=search). `foreach` is irrelevant to the question. – deceze Sep 03 '11 at 06:16

2 Answers2

0

CakePHP has a basic MVC (Model, View, Controller) concept. If you call a controller or model from a view, you do something they don't wan't let you do.

It's a better practice to create a helper, which you can access from the view.

evotopid
  • 5,288
  • 2
  • 26
  • 41
0

you are breaking MVC. You should have all the data readied in the controller, before rendering the view.

Anh Pham
  • 5,431
  • 3
  • 23
  • 27