0

我的网站有些问题。我想要这个视图做的是显示与用户 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
4

2 回答 2

1

这可能是网址的问题

尝试这个

<?php echo $this->Html->link('Invoice',
    array('controller' => 'invoices', 
          'action' => 'payinvoice', 
          $invoice['Invoice']['id'])
    );?>

它会产生

<a href="/invoices/payinvoice/6">Invoice</a>
于 2012-05-23T17:10:36.390 回答
1

看起来您没有将 id 传递到您的页面中。网址应如下所示:

/invoices/payinvoice/2
于 2012-05-23T14:05:38.480 回答