Hi

I'm using CakePHP version 1.2 RC3. I have a table called 'sites' which
is basically a hierarchy or tree of sites with Plant Earth at the top
and fintering down through continents, counties, states, towns etc.
Each site record has a parent ID that links to the next site up the
tree. My model reflects this:

    class Site extends AppModel {
        var $name = "Site";

                var $hasMany = array(
                        'Sites' => array('ClassName' => 'Site',
                                                'foreignKey' => 'parent_id'));
                var $belongsTo = array(
                        'Sites' => array('ClassName' => 'Site',
                                                'foreignKey' => 'parent_id'),
                        'Users' => array('ClassName' => 'User',
                                                'foreignKey' => 'user_id')
                        );

(The site also belongs to an application user).

If I create a controller to use scaffolding this works very well. When
I add a site it produces a drop down list of sites so I can select the
parent site. Very nice.

However I wanted to go beyond scaffolding and so I baked a new
controller using cake bake. However this new controller gives an error
when I try to run the add method. Here's the error:

Notice (8): Undefined property:  Site::$Site [APP/controllers/
sites_controller.php, line 31]

Code

            }
        }
        $sites = $this->Site->Site->find('list');

SitesController::add() - APP/controllers/sites_controller.php, line 31
Object::dispatchMethod() - CORE/cake/libs/object.php, line 114
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 259
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 213
[main] - APP/webroot/index.php, line 90


Fatal error: Call to a member function find() on a non-object in /var/
www/birdspotter/app/controllers/sites_controller.php on line 31

and here's the method:

        function add() {
                if (!empty($this->data)) {
                        $this->Site->create();
                        if ($this->Site->save($this->data)) {
                                $this->Session->setFlash(__('The Site has been 
saved', true));
                                $this->redirect(array('action'=>'index'));
                        } else {
                                $this->Session->setFlash(__('The Site could not 
be saved. Please,
try again.', true));
                        }
                }
                $sites = $this->Site->Site->find('list');
                $users = $this->Site->User->find('list');
                $this->set(compact('sites', 'users'));
        }

This controller doesn't appear to recognize the relationship between a
site and it's parent. Given that the scaffold has no problem with this
relationship why doesn't the baked controller get it right?

Is there a simple fix for the baked controller? The edit method has
the same problem.

Thanks

David
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to