這是動作URL如何在蛋糕的PHP取從兩個表中的數據
http://localhost/carsdirectory/cars/home
cars_controller.php(控制器)
public function home(){
$this->set('latest_cars', $this->Car->find('all', array(
'order' => array(
'Car.modified DESC',
'Car.created Desc'
),
'limit' => '3'
)));
$this->set('galleries', $this->Gallery->find('all'));
}
car.php(模型)
public $hasMany = array(
'Gallery' => array(
'className' => 'Gallery',
'foreignKey' => 'car_id',
'dependent' => true
)
);
(模特)
var $belongsTo = array(
'Car' => array(
'className' => 'Car',
'foreignKey' => 'car_id',
)
);
home.ctp(視圖)
<?php foreach($latest_cars as $latest_car){ ?>
<img src="img/car-listings.jpg" /> // now it's static
<h4><?php echo $latest_car['Car']['car_name']; ?></h4> // it's dynamic it's coming car table
<span>$<?php echo $latest_car['Car']['car_price']; ?></span> // it's dynamic it's coming car table
<?php } ?>
我有替換線
<img src="img/car-listings.jpg" />
與線
<?php $this->Html->image('/media/filter/small/'.$latest_cars['Gallery']['dirname'].'/'.$latest_cars['Gallery']['basename']);?>
但即時得到該錯誤
未定義指數:膽ERY [APP \視圖\汽車\ home.ctp,線226]
<img src="img/car-listings.jpg" /> 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
這是畫廊表結構
ID - 1
基名 - chrysanthemum_10.jpg
car_id - 1
在此先感謝
我已經加入car.php public $ hasMany = array( \t'Gallery'=> array( \t'class名稱」 => '廊', \t 'FOREIGNKEY'=> 'car_id', \t '依賴'=>真 \t \t) \t);和gallery.php變量$屬於關聯=陣列( \t \t \t '汽車'=>數組( \t \t \t \t '的className'=> '汽車', \t \t \t \t 'FOREIGNKEY'=> 'car_id', \t) );但我得到那味精未定義的索引:畫廊[APP \ views \ cars \ home.ctp,第226行],可以幫助我更多PLZ – 2012-03-12 07:44:47
您使用'遞歸'或可容納? – ori 2012-03-12 08:11:00
先生ori,我沒有關於遞歸或包含,即時新的蛋糕PHP,但我已編輯我的問題,所以PLZ你可以檢查現在 – 2012-03-12 08:17:09