Model 检索';属于';cakephp中的部分模型数据

Model 检索';属于';cakephp中的部分模型数据,model,cakephp-1.3,belongs-to,cakephp-model,Model,Cakephp 1.3,Belongs To,Cakephp Model,也许是因为我太累了,但我完全错过了一些东西。我从一个朋友那里继承了一个cake 1.3应用程序,他的表设置正确,但我丢失了一些数据。当我打印数据数组时,我期望的是: Array ( [Listing] => Array ( [id] => 74 [listing_name] => El Toro [category_id] => 3 [location_id] => 2 [lo

也许是因为我太累了,但我完全错过了一些东西。我从一个朋友那里继承了一个cake 1.3应用程序,他的表设置正确,但我丢失了一些数据。当我打印数据数组时,我期望的是:

 Array
(
[Listing] => Array
    (
        [id] => 74
        [listing_name] => El Toro
        [category_id] => 3
        [location_id] => 2
        [long_desc] => 
    ),

[Category] => Array
    (
        [id] => 3
        [category_name] => Restaurant

    ),
)
(列表属于STO类别)。控制器功能的定义如下:

function view_detail(){

    $this->set('um','true');
    $l=$this->Listing->find('first', array('conditions'=>array('id'=>$this->params['cid'])));
    $this->set('lst', $l);


}
相反,我得到的是:

 Array
(
[Listing] => Array
    (
        [id] => 74
        [listing_name] => El Toro
        [category_id] => 3
        [location_id] => 2
        [long_desc] => 
    )
)
通过查看他设置的数据库表,cake的所有约定都得到了遵守:列表有category_id,categories有listing_id。我相信不久前有人告诉我,如果你有简单的cookie cutter模型/关联,你甚至不需要设置模型页面,因为cake会自动知道这些关联。但我还是做了,没有什么不同。我尝试将递归设置为2,但没有任何区别。Sooooo…不擅长cakephp,我不知道我做得不对。顺便说一下,我想列出清单中的类别名称(餐厅)

更新

以下是我的两个型号:

class Category extends AppModel{

var $hasMany = array( 'Listing' );

}


class Listing extends AppModel{
var $name='Listing';
var $belongsTo = array( 'Location'=>array('foreignKey'=>'location_id'),   'Category'=>array('foreignKey'=>'category_id') );

}

在1.x中,模型文件应该小写并加下划线,因此
app/model/listing.php

当您的模型类显示为AppModel时,这意味着cake没有找到您的模型类并基于AppModel创建一个通用类。

categories.listing\u id是错误的/不必要的。你确定你有
public$belongsTo=array('Category')
public$hasMany=array('Listing')
Category
model?categories.listing\u id只是在我键入这些数组时意外包含的(对不起,实际上不在数据库表中!)。列表模型和类别模型都具有正确的belongsTo和hasMany语法。这是cake 1.3,所以我只使用var$hasMany等,而不是public$hasMany。调试(get_class($This->Listing))
的输出是什么?是AppModel还是Listing?递归应该可以工作,但尝试可包含的行为不会有什么坏处。这就是你的问题。您的清单模型的文件名、路径(相对于应用程序目录)和类名是什么?它是/app/models/Listing.php,我在Listing.php或Category.php中都没有声明类名。我一直在使用Cake 2.x的命名约定