I’m trying to create a page that will spit out a users invoices. I am having trouble with the retrieval of specific users invoices. The issue is with the function in the controller and setting the $id. I’m not sure how to set it to the current user.
Here is the relevant code in my function
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));
}
This is the answer
included my view:
<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>
in the code I have it hard coded so user 15 can view all his invoices but I don’t want my system hard coded. I want it to be set to $id='currentuser' but am unsure of how to code it.
users login function
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');
}
}
any help would be greatly appreciated
For current user you need to have the session, Im assuming the session contains user_id.
Try this