1
我純粹是cakephp的新手,目前正在構建1.3
版本的項目。基本上我試圖顯示插入到數據庫中的提供者的城市名稱。我有兩個型號:gal_store.php
和gal_location.php
。在gal_store
模型中,商店名稱與其對應的城市ID保存在gal_stores
表中的city
字段中。表gal_locations
包含所有的城市和他們的名字。不在cakephp中工作的模型(JOIN)的關聯顯示空的結果
於是,我就加入這兩個表如下:
var $hasOne = array(
'GalLocation' => array(
'className' => 'GalLocation',
'foreignKey' => 'id',
'conditions' => '',
'fields' => '',
'order' => ''
),
);
function getList($limit = 50,$whether_list = false){
$recursive = -1;
$conditions = array("GalStore.city"=> "GalLocation.id");
//$conditions = "";
$order = array("GalStore.address");
if($whether_list == true){
return $this->find("list",array("DISTINCT GalStore.city","recursive"=>$recursive,"limit"=>$limit,"order"=>$order,"conditions" => $conditions));
}else{
return $this->find("all",array("DISTINCT GalStore.city","recursive"=>$recursive,"limit"=>$limit,"order"=>$order,"conditions" => $conditions));
}
}
但在ctp
文件時,我做了var_dump($gal_locations);
它總是顯示爲空!是什麼原因 ?