这是我在zend框架中的Controller
编码
public function homeAction() {
$storage = new Zend_Auth_Storage_Session();
$data = $storage->read();
if (!$data) {
$this->_redirect('admin/login');
}
$this->view->storeid = $data->storeid;
$iExtStoreId = $data->storeid; // admin storeid
$db = Zend_Db_Table::getDefaultAdapter();
$sql = "SELECT storeId FROM stores where extStoreId= '$iExtStoreId' ";
$result = $db->fetchAll($sql);
$sStoreId = $result[0]['storeId'];
if (strlen($sStoreId) >= 32) {
$sql = "select * from voucherRedemptions where storeId='$sStoreId'";
$result2 = $db->fetchAll($sql);
} else {
$result2 = array();
}
echo "<table border='1'>
<tr>
<th>redemptionId</th>
<th>voucherId</th>
<th>storeId</th>
<th>redemptionTime</th>
</tr>";
if (count($result2) > 0) {
foreach ($result2 as $row) {
echo "<tr>";
echo "<td>" . $row['redemptionId'] . "</td>";
echo "<td>" . $row['voucherId'] . "</td>";
echo "<td>" . $row['storeId'] . "</td>";
echo "<td>" . $row['redemptionTime'] . "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='4'>Data not found </td></tr>";
}
echo "</table>";
}
现在我想将视图code
保留在view
文件夹home.html
what i can do ?
答案 0 :(得分:1)
不要echo
控制器中的所有内容。这就是view
的用途。
设置所有viewvariables后:
$this->render('/path/to/home.html');
打印那里的所有东西。
另请注意,Zend Framework有pretty good documentation available。
答案 1 :(得分:1)
我对Zend Framework没有太高的速度,但是继续PeeHaa的回答和粗略的知识,我猜你的控制器看起来像这样:
class YourController {
public function indexAction() {
$view = new Zend_View();
$view->someVar = 'Some Value.';
$view->render('/admin/admin.phtml');
}
}
然后在您的admin.phtml
模板中
<!-- should output "Some Value." -->
<p><?php echo $this->someVar; ?></p>