I'm beginning with Zend_Cache. I would like to ask your help on caching DB relational data in controller and view script.
I called my db model from my controller and assigned it to a view variable. In order to get a list similar to below, I used _findDependentRowSet in the view script to use less loops:
Category name
- Column 1
......
- Column 7
=====- Names that should be in this column
- Column 2- Names that should be in this column
- Column 3......
- Column 7
SQL
=====
CREATE TABLE IF NOT EXISTS `naadam_serial` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(200) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
CREATE TABLE IF NOT EXISTS `naadam_serial_data` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`naadam_serial_id` int(11) DEFAULT NULL,
`place` int(11) DEFAULT NULL,
`azarga` varchar(200) DEFAULT NULL,
`ih_nas` varchar(200) DEFAULT NULL,
`soyoolon` varchar(200) DEFAULT NULL,
`hyazaalan` varchar(200) DEFAULT NULL,
`shvdlen` varchar(200) DEFAULT NULL,
`daaga` varchar(200) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `naadam_serial_id` (`naadam_serial_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=24 ;
======
In the Controller
======
$naadams = new BEREGU_Model_NaadamSerial();
$this->view->naadams = $naadams->fetchAll();
======
In the View Script
======
foreach ($this->naadams as $naadam){
$datas = $naadam->findDependentRowset('BEREGU_Model_NaadamSerialData');
$i = 0; //Originally I used html table in my view script. To print the
<table>
foreach ($datas as $data){
<td><?php echo $data->azarga; ?></td>
<td><?php echo $data->ih_nas; ?></td>
<td><?php echo $data->soyoolon; ?></td>
<td><?php echo $data->hyazaalan; ?></td>
<td><?php echo $data->shvdlen; ?></td>
<td><?php echo $data->daaga; ?></td>
</tr>
}
</table>
}$i = 0; //Originally I used html table in my view script. To print the
<table>
foreach ($datas as $data){
if ($i == 0){ //To print column names only once
if (null != $data->azarga){
<th>Azarga</th>
}
if (null != $data->ih_nas):{
<th>Ih nas</th>
}
if (null != $data->soyoolon){
<th>Soyoolon</th>
}
if (null != $data->hyazaalan){
<th>Hyazaalan</th>
}
if (null != $data->shvdlen){
<th>Shvdlen</th>
}
if (null != $data->daaga){
<th>Daaga</th>
}
</tr>
$i = 1;
}
<tr>
<td><?php echo $data->place; ?></td> <tr>
<th><h2>echo $naadam->name;</h2></th>
</tr><tr>
<th>Place</th>if (null != $data->azarga){
<th>Azarga</th>
}
if (null != $data->ih_nas):{
<th>Ih nas</th>
}
if (null != $data->soyoolon){
<th>Soyoolon</th>
}
if (null != $data->hyazaalan){
<th>Hyazaalan</th>
}
if (null != $data->shvdlen){
<th>Shvdlen</th>
}
if (null != $data->daaga){
<th>Daaga</th>
}
</tr>
$i = 1;
}
<tr>
<td><?php echo $data->azarga; ?></td>
<td><?php echo $data->ih_nas; ?></td>
<td><?php echo $data->soyoolon; ?></td>
<td><?php echo $data->hyazaalan; ?></td>
<td><?php echo $data->shvdlen; ?></td>
<td><?php echo $data->daaga; ?></td>
</tr>
}
</table>
How can I cache both db data? One is called in the controller and the other one is called in the view script as a dependent. If you have any sample code or tutorial link, please let me know.
Thank you friends!
---
Enkhbilguun Erdenetsogt
没有评论:
发表评论