Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Have you properly set up your <a href="http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html" rel="nofollow">model associations</a>? If so you should be able to do something like <code>$invoice['Client']['client_name']</code> assuming you didn't use <code>recursive = -1</code>.</p> <p>/edit: Ok I don't mind throwing some code out, but this is a fundamental concept you'll have to try to wrap your head around. Every model that is connected to another model has to have the association set up or things will be painful.</p> <p>I am assuming a <code>Client hasMany Invoice</code>. So each invoice is specific to a client, and they can have multiple invoices (ex. October 2013 vs November 2013 invoice). From the CakePHP page we see:</p> <pre><code>class User extends AppModel { public $hasMany = array( 'Comment' =&gt; array( 'className' =&gt; 'Comment', 'foreignKey' =&gt; 'user_id', 'conditions' =&gt; array('Comment.status' =&gt; '1'), 'order' =&gt; 'Comment.created DESC', 'limit' =&gt; '5', 'dependent' =&gt; true ) ); } </code></pre> <p>So using that as our template, we end up with:</p> <pre><code>public $hasMany = array( 'Invoice' =&gt; array( 'className' =&gt; 'Invoice', 'foreignKey' =&gt; 'client_id' ) ); </code></pre> <p>And that goes in <code>Client.php</code>. As the inverse of <code>hasMany</code> is <code>belongsTo</code>, we have an <code>Invoice belongsTo Client</code>. Again, using the CakePHP page as the template, we end up with:</p> <pre><code> public $belongsTo = array( 'Client' =&gt; array( 'className' =&gt; 'Client', 'foreignKey' =&gt; 'client_id' ) ); </code></pre> <p>And that goes in <code>Invoice.php</code>. Once you set up those associations, whenever you do something like <code>$this-&gt;Invoice-&gt;find('all');</code> or <code>$this-&gt;paginate('Invoice');</code>, with proper <code>$recursive</code> settings, Cake will grab the corresponding <code>Client</code> record. This allows you to do what I said before, something like <code>$invoice['Client']['client_name']</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload