CakePHP - Undefined Property when trying $this->Restaurant->City->find('list');
I'm trying to allow an admin 开发者_StackOverflow中文版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).
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.
精彩评论