我正在尝试创建一个会吐出用户发票的页面。我在检索特定用户发票时遇到问题。问题在于控制器中的功能和设置 $id。我不确定如何将其设置为当前用户。
这是我函数中的相关代码
public function payInvoice(){
$this->set('title_for_layout', 'Pay Invoice');
$this->set('stylesheet_used', 'homestyle');
$this->set('image_used', 'eBOXLogoHome.jpg');
$this->layout='home_layout';
$userid = $this->Auth->user('id');
$this->set('Invoices', $this->Invoice->findByBiller($userid));
}
这是包含我观点的答案:
<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>
<td align='center'><?php echo $this->Html->link($Invoices['Invoice']['to'],
array('action' => 'viewInvoice', $Invoices['Invoice']['to'])); ;?> </td>
<td align='center'><?php echo $Invoices['Invoice']['subject']; ?></td>
<td align='center'><?php echo $Invoices['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>
在代码中,我对其进行了硬编码,因此用户 15 可以查看他的所有发票,但我不希望我的系统被硬编码。我希望将其设置为,$id='currentuser'
但不确定如何对其进行编码。
用户登录功能
public function login() {
$this->set('title_for_layout', 'Individual Registration');
$this->set('stylesheet_used', 'style');
$this->set('image_used', 'eBOXLogo.jpg');
if ($this->request->is('post')){
$this->request->data['User']['password'] = 'qazwsx';
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect('eboxs/home'));
$this->Session->write('Myid',$myid);
}
else {
$this->Session->setFlash('Username or password is incorrect');
}
}else{
$this->Session->setFlash('Welcome, please login');
}
}
任何帮助将不胜感激