这是我当前的模式 - 部分显示。
CREATE TABLE cart (
username VARCHAR(60),
productid INT(5),
quantity INT(6),
PRIMARY KEY (username, productid),
FOREIGN KEY (username) REFERENCES login(username),
FOREIGN KEY(productid) REFERENCES product(productid)
);
CREATE TABLE product (
productid INT(5) NOT NULL AUTO_INCREMENT,
name VARCHAR(30) NOT NULL,
description VARCHAR(1000),
price VARCHAR(6) NOT NULL,
stocks INT(6) NOT NULL,
PRIMARY KEY (productid)
);
我的 CartController 中有这个功能:
public function indexAction()
{
$auth= Zend_Auth::getInstance();
$user= $auth->getIdentity();
$username = $user->username;
$cart = new Application_Model_DbTable_Cart();
$fetch = $cart->fetchAll($cart->select()->where('username = ?', $username));
$this->view->cart = $fetch;
}
我的 index.phtml 正在调用它:
<?php foreach($this->cart as $cart) :?>
<tr>
<td><?php echo $this->escape($cart['productid']);?></td>
<td></td>
<td><?php echo $this->escape($cart['quantity']);?></td>
<td></td>
<td>
<a href="<?php echo $this->url(array('controller'=>'product',
'action'=>'edit', 'id'=>$product->productid));?>">Edit</a>
</td>
<td>
<a href="<?php echo $this->url(array('controller'=>'product',
'action'=>'delete', 'id'=>$product->productid));?>">Delete</a>
</td>
</tr>
<?php endforeach; ?>
在表格中显示产品名称和价格的最优雅的方式是什么?