in controller have method
<?php function test($value){ $products = $this->model->getproducts($id); for($i=0; $i < count($products); $i++){ foreach ($products[$i] $key => $value) { return $value; } } } ?>
how can access inside view?
if generate variable in controller, , want access in view, can use
$this->set('value', $value);
this allow use $value in relevant view well.
if want access function view, don't want want put function in controller, in helper. (as rule of thumb, put functions want accessible views in helpers, , functions want accessible controller in components.) might worth reading more on helpers in cake cookbook etc if don't know start!
edit: getting relevant values of loop, try like:
$products = $this->model->getproducts($id); $results = array(); for($i=0; $i < count($products); $i++){ foreach ($products[$i] $key => $value) { $results[] = $value; } } $this->set(compact('results'));
Comments
Post a Comment