我有什么:
我有一个名为销售的表和3个名为卖方,买方和价格的列。
在控制器中,我有一个函数myview(),我在这里执行SQL查询:
SELECT SUM(price) AS total, seller_name, buyer_name
FROM sales
GROUP BY seller_name, buyer_name
功能:
public function myview() {
$this->set('mysales', $this->Sales->find('all',
array(
'fields' => array('SUM(price) AS total','seller_name','buyer_name'),
'group' => array('seller_name','buyer_name')
)
));
}
我在 myview.ctp 中显示结果:
<table>
<tr>
<th>Seller</th>
<th>Buyer</th>
<th>Total</th>
<th>PDF</th>
</tr>
<?php
foreach ($mysales as $thesales)
{
?>
<tr>
<td><?php echo $thesales['Sales']['seller_name']; ?></td>
<td><?php echo $thesales['Sales']['buyer_name']; ?></td>
<td><?php echo $thesales[0]['total']; ?></td>
<td><input type="button" onclick="location.href='myview_pdf';" value="PDF"/></td>
</tr>
</table>
<?php
}
echo $this->Js->writeBuffer();
?>
PDF按钮将您带到另一个名为 myview_pdf 的视图,其中显示(现在)空白PDF。
我想要的是什么:
当您点击PDF按钮时,它会识别&#34; &#39; seller_name&#39;以及&#39; buyer_name&#39;我单击按钮的行所以我可以执行此SQL查询:
SELECT price, seller_name, buyer_name
FROM sales
GROUP BY seller_name, buyer_name
并将结果显示在 myview_pdf.ctp
中问题:
我正在努力:我怎么知道我点击了哪一行,如何从行中获取数据,在哪里编写SQL查询,如何将查询结果传递给myview_pdf.ctp ..
感谢您的帮助!
答案 0 :(得分:0)
您需要首先将其设为链接而不是按钮,并将卖家和买家名称作为查询字符串传递。
<td>
<!-- <input type="button" onclick="location.href='myview_pdf';" value="PDF"/> --> <!-- Remove this -->
<?php echo $this->Html->link("PDF", array(
"controller" => "<controller name>",
"action" => "myview_pdf",
"?" => array(
"seller_name" => $thesales['Sales']['seller_name'];,
"buyer_name" => $thesales['Sales']['buyer_name'];,
)
)); ?>
然后在您的控制器中,您可以从查询字符串中访问卖家和买家名称:
public function myview_pdf() {
$seller_name = $this->request->query("seller_name");
$buyer_name = $this->request->query("buyer_name");
/* Other code */
}