CakePHP - 尝试 $this->Restaurant->City->find('list'); 时未定义属性

发布于 2024-10-30 01:36:58 字数 550 浏览 1 评论 0原文

我试图允许管理员编辑“餐厅” - 他们需要能够更改的事情之一是餐厅所在的城市。所以 - 我试图通过restaurants_controller.php将“城市”表中的城市列表传递给我的/restaurants/admin_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 获取城市列表的解释

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

I'm trying to allow an admin to edit "restaurants" - one of the things they need to be able to change is the city where the restaurant is located. So - I'm trying to pass the list of cities in my "cities" table to my /restaurants/admin_edit.ctp via the 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

I hope / assume this is a stupid issue and something I'm just doing wrong since I'm new to CakePHP, but after an hour and a half searching, I cannot find an explanation of how I can get the list of cities from the restaurants_controller.php

I have set up my hasOne in the restaurant.php model, and my belongsToMany in my city.php model (not sure if that matters).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

递刀给你 2024-11-06 01:36:58

所以——问题是,我的联想消失了。我误解了这些关联,但是在阅读这篇非常有用的文章之后,我重写了我的关联(有很多,属于...等),瞧 - “查找”工作完美。

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

So - the issue was, my associations were off. I missunderstood the associations, but after reading this incredibly helpful article, I rewrote my associations (hasMany, belongsTo...etc), and voila - the "find" worked perfectly.

I also found a few places that said I could use a $uses variable, but I found a few other places that dismissed that immediately, and said to just use correct associations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文