Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So, you have a <code>Car</code> model and a <code>Gallery</code> model. Since <code>Gallery</code> has a <code>car_id</code> property, it can be used to form these CakePHP <a href="http://book.cakephp.org/1.3/view/1039/Associations-Linking-Models-Together" rel="nofollow">Associations</a>:</p> <blockquote> <p>Gallery belongsTo Car</p> </blockquote> <p>and</p> <blockquote> <p>Car hasOne Gallery</p> </blockquote> <p>You can choose which associations you actually need and define them in your models. In your case, you want to show the car's gallery when querying for cars, so:</p> <pre><code>// in car.php var $hasOne = 'Gallery'; </code></pre> <p>Then you can choose whether you want to use <a href="http://book.cakephp.org/1.3/en/view/1323/Containable" rel="nofollow">Containable</a> to control which associations get included in queries, or just use <code>recursive</code> to include all of them:</p> <pre><code>// in cars_controller.php $this-&gt;set('latest_cars', $this-&gt;Car-&gt;find('all', array( 'recursive' =&gt; 1, 'order' =&gt; array( 'Car.modified DESC', 'Car.created Desc' ), 'limit' =&gt; '3' ))); </code></pre> <p>Then in your view, use <code>$latest_car['Car']</code> to access the car properties and <code>$latest_car['Gallery']</code> to access the gallery properties</p> <p><strong>EDIT</strong></p> <p>If a <code>Car</code> hasMany <code>Gallery</code>, then you should expect this structure:</p> <pre><code>[0] =&gt; Car =&gt; (first car) Gallery =&gt; [0] =&gt; (first gallery of first car) [1] =&gt; (second gallery of first car) [1] =&gt; Car =&gt; (second car) Gallery =&gt; [0] =&gt; (first gallery of second car) etc. </code></pre> <p>so to access it in your view:</p> <pre><code>&lt;?php foreach($latest_cars as $latest_car){ foreach ($latest_car['Gallery'] as $gallery) echo $this-&gt;Html-&gt;image('/media/filter/small/'.$gallery['dirname'].'/'.$gallery['basename']); ?&gt; </code></pre>
    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.
    3. 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