views:

409

answers:

1

hi all,

i am using zend framework to develop my php applications using mvc model.

i want to generate some reports from database. but i dont know how to separate models and views in this case.

i fetch information from db, then i should iterate through them and make a html table. then pass this table to a class, making pdf file from the html table.

how should i make this html table in my view then pass it to my model and generating pdf file?!

A: 
//in controller
$this->view->data = $model->getData($parameter);

//in model
pulic function getData($parameter)
{
  $sql = $this->select()->where('parameter = ?',$parameter);
  return $this->fetchAll($sql);
}

//in view
...
foreach($this->data as $item)
{
  echo '<tr>';
  echo '<td>';
  echo $item->name;
  echo '</td>';
  echo '</tr>';
}
Tomáš Fejfar
as i told, i dont want to echo my table. i want to put my table in a variable and pass the variable to a class method and make a pdf file from it.
rahim asgari
so leave the data as it is and do the "foreach" in your PDF generator :)
Tomáš Fejfar
ok, i think i should do this so. but i thought that if i do the foreach in my PDF generator which is a model class and generate html tables in it i am mixing views and models.
rahim asgari