0

I'm having some trouble with my site. What I want this view to do is display all invoices that relates to a userid(in another table), Instead the code is printing out all the invoices in the one view(disregarding the user id). When looking at the sql statement that cakephp debug spits out it shows the where as a blank(don't worry I'll include the actual sql statment). I also have session code created but I am unsure how to code it so that the mysql data will say where userid = current user;

here is the code for the view

<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>

here is the code in the class relating to this view

 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)))); 
} 

and here is the sql code that site is using to retrieve the data

   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

2 Answers 2

1

It looks like you are not passing an id into your page. The url should look like:

/invoices/payinvoice/2
Sign up to request clarification or add additional context in comments.

2 Comments

how would one be able to achieve that?
See Moyed Ansari's answer above
1

This is probably the issue of the url

try this

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

it will generate

<a href="/invoices/payinvoice/6">Invoice</a>

2 Comments

it comes up with a link on the site but its only 'invoices/payinvoice/'
Can you post the code you use to populate $invoice and the output of debug[$invoice] please?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.