我的网站有些问题。我想要这个视图做的是显示与用户 ID 相关的所有发票(在另一个表中),而不是代码在一个视图中打印出所有发票(忽略用户 ID)。当查看 cakephp 调试吐出的 sql 语句时,它将 where 显示为空白(别担心,我会包含实际的 sql 语句)。我也创建了会话代码,但我不确定如何对其进行编码,以便 mysql 数据将说明 where userid = current user;
这是视图的代码
<table width="100%" border="1">
<table width="100%" border="1">
<tr>
<th>Biller</th>
<th>Subject</th>
<th>Date</th>
<th>Action</th>
</tr>
<?php foreach($invoices as $invoice):?>
<tr> debug($invoices);
<td align='center'><?php echo $this->Html->link($invoice['Invoice']['biller'],
array('action' => 'viewinvoice', $invoice['Invoice']['id'])); ;?> </td>
<td align='center'><?php echo $invoice['Invoice']['subject']; ?></td>
<td align='center'><?php echo $invoice['Invoice']['datecreated']; ?></td>
<td align='center'><a href="viewinvoice"><button>View Invoice</button></a><a href="disputeinvoice"><button>Dispute Invoice</button></a></td>
</tr>
<?php endforeach; ?>
</table>
这是与此视图相关的类中的代码
public function payinvoice($id = null){
$this->set('title_for_layout', 'Pay Invoice');
$this->set('stylesheet_used', 'homestyle');
$this->set('image_used', 'eBOXLogoHome.jpg');
$this->layout='home_layout';
$this->set('invoices', $this->Invoice->find('all' , array('conditions' => array('Invoice.biller' => $id))));
}
这是该站点用于检索数据的 sql 代码
SELECT `Invoice`.`id`, `Invoice`.`to`, `Invoice`.`biller`, `Invoice`.`subject`, `Invoice`.`description`, `Invoice`.`amount`, `Invoice`.`datecreated`, `Invoice`.`duedate` FROM `pra_cake`.`invoices` AS `Invoice` WHERE `Invoice`.`biller` IS NULL