Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to fetch data from two table in cake php
    primarykey
    data
    text
    <p>this is action url</p> <p><a href="http://localhost/carsdirectory/cars/home" rel="nofollow">http://localhost/carsdirectory/cars/home</a></p> <p>cars_controller.php(controller)</p> <pre><code>public function home(){ $this-&gt;set('latest_cars', $this-&gt;Car-&gt;find('all', array( 'order' =&gt; array( 'Car.modified DESC', 'Car.created Desc' ), 'limit' =&gt; '3' ))); $this-&gt;set('galleries', $this-&gt;Gallery-&gt;find('all')); } </code></pre> <p>car.php(model)</p> <pre><code> public $hasMany = array( 'Gallery' =&gt; array( 'className' =&gt; 'Gallery', 'foreignKey' =&gt; 'car_id', 'dependent' =&gt; true ) ); </code></pre> <p>gallery.php(model)</p> <pre><code> var $belongsTo = array( 'Car' =&gt; array( 'className' =&gt; 'Car', 'foreignKey' =&gt; 'car_id', ) ); </code></pre> <p>home.ctp(view)</p> <pre><code>&lt;?php foreach($latest_cars as $latest_car){ ?&gt; &lt;img src="img/car-listings.jpg" /&gt; // now it's static &lt;h4&gt;&lt;?php echo $latest_car['Car']['car_name']; ?&gt;&lt;/h4&gt; // it's dynamic it's coming car table &lt;span&gt;$&lt;?php echo $latest_car['Car']['car_price']; ?&gt;&lt;/span&gt; // it's dynamic it's coming car table &lt;?php } ?&gt; </code></pre> <p>i have replace that line </p> <pre><code> &lt;img src="img/car-listings.jpg" /&gt; </code></pre> <p>with that line</p> <pre><code> &lt;?php $this-&gt;Html-&gt;image('/media/filter/small/'.$latest_cars['Gallery']['dirname'].'/'.$latest_cars['Gallery']['basename']);?&gt; </code></pre> <p>but i m getting that error</p> <p>Undefined index: Gallery [APP\views\cars\home.ctp, line 226]</p> <pre><code> &lt;img src="img/car-listings.jpg" /&gt; this line i want to make dynamic , so my question how to use join in cars_controller or any other idea and i want to fetch data from galleries table </code></pre> <p>this is galleries table structure</p> <p>id - 1</p> <p>basename - chrysanthemum_10.jpg </p> <p>car_id - 1</p> <p>thanks in advance</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. This table or related slice is empty.
    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