这是动作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