Note that there are some explanatory texts on larger screens.

plurals
  1. PODatabase table to make drop down select using cakephp
    text
    copied!<p>I have one controller for invoices and another for clients. </p> <p>I have made some "relationships" in the models of these controllers as below: </p> <p><strong>Client.php</strong></p> <pre><code>&lt;?php class Client extends AppModel { public $hasMany = array( 'Invoice' =&gt; array( 'className' =&gt; 'Invoice', 'foreignKey' =&gt; 'client_id' ) ); } ?&gt; </code></pre> <p><strong>Invoice.php</strong></p> <pre><code>&lt;?php class Invoice extends AppModel { public $belongsTo = array( 'Client' =&gt; array( 'className' =&gt; 'Client', 'foreignKey' =&gt; 'client_id' ) ); } ?&gt; </code></pre> <p>So I thought that making a drop down with each client would be easy. Although, I can't figure out how to do this. </p> <p>First off this is what I want as a result: </p> <pre><code>&lt;select&gt; &lt;option value="1"&gt;Client Name&lt;/option&gt; &lt;/select&gt; </code></pre> <p>Where value is equal to id in client table and Client Name is equal to name in client table.</p> <p>I tried placing the following into the invoices controleler: </p> <pre><code>$client = $this-&gt;Client-&gt;find('all'); </code></pre> <p>and then the following into my view: </p> <pre><code>echo $this-&gt;Form-&gt;select('client_name',client, array( 'class' =&gt; 'form-control', 'name' =&gt; 'client_id' )); </code></pre> <p>But I received the following error: </p> <pre><code>Call to a member function find() on a non-object </code></pre> <p>Directly on page load. What do I need to do to make this work?</p>
 

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