Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CakePHP-尝试$this时未定义属性->;餐厅->;城市->;查找(';列表';);_Php_Cakephp_Cakephp 1.3 - Fatal编程技术网

CakePHP-尝试$this时未定义属性->;餐厅->;城市->;查找(';列表';);

CakePHP-尝试$this时未定义属性->;餐厅->;城市->;查找(';列表';);,php,cakephp,cakephp-1.3,Php,Cakephp,Cakephp 1.3,我正在尝试允许管理员编辑“餐馆”-他们需要能够改变的事情之一是餐馆所在的城市。因此,我试图通过restaurants\u controller.php将“cities”表中的城市列表传递给my/restaurants/admin\u edit.ctp function admin_edit($id = null) { $this->set('cities', $this->Restaurant->City->find( 'list', array(

我正在尝试允许管理员编辑“餐馆”-他们需要能够改变的事情之一是餐馆所在的城市。因此,我试图通过restaurants\u controller.php将“cities”表中的城市列表传递给my/restaurants/admin\u edit.ctp

function admin_edit($id = null) {
    $this->set('cities', $this->Restaurant->City->find(
        'list', array('order' => 'City.name', 'fields' => 'City.id, City.name')));

        ...etc
我希望/假设这是一个愚蠢的问题,我只是做错了,因为我是CakePHP新手,但经过一个半小时的搜索,我找不到如何从restaurants_controller.php获取城市列表的解释

function admin_edit($id = null) {
    $this->set('cities', $this->Restaurant->City->find(
        'list', array('order' => 'City.name', 'fields' => 'City.id, City.name')));

        ...etc

我已经在restaurant.php模型中设置了我的hasOne,在my city.php模型中设置了我的belongTomany(不确定这是否重要)。

所以-问题是,我的关联被关闭了。我误解了这些联想,但读完后,我重写了我的联想(hasMany,belongsTo…等等),瞧,“发现”工作得很好


我还发现了一些地方说我可以使用$uses变量,但我发现了一些其他地方立即否定了这一点,并说只使用正确的关联。

是的,如果关联正确,通常不需要使用$uses。如果您发现自己经常使用
$uses
,也许是时候重新考虑一下您的数据库设计了。我想是的,但总是很高兴听到其他人验证:)谢谢。