Problem with function call in CakePHP

Question:

I have this in the Passagem.php model:

<?php
class Passagem extends AppModel {
    public $name = 'Passagem';
}?>

And this in PassagesController.php:

<?php
class PassagensController extends AppController {
    public $helpers = array('Html','Form');
    public $name = 'Passagens';
    public $components = array('Session');

    function index(){
        $this->set('passagens', $this->Passagem->find('all'));
    }
}?>

The moment I access the Passages page, I get an error with this description:

"Error: Call to a member function find() on a non-object File: C:\wamp\www\PassSales\app\Controller\PassagensController.php Line: 8"

Note: In the project there are other Models and Controllers. But only in "Passages" this error occurs.

What can it be?

Answer:

Try this:

In your PassagesController add the $uses as below:

<?php
class PassagensController extends AppController {
   public $helpers = array('Html','Form');
   public $name = 'Passagens';
   public $components = array('Session');
   public $uses = array('Passagem');

   function index(){
      $this->set('passagens', $this->Passagem->find('all'));
   }

}?>
Scroll to Top