Cakephp ignoring my Model

Asked

Viewed 90 times

0

Why is cake ignoring my Model? I don’t understand. I have several other models working perfectly, but this one is not working. It is being ignored.

Model name: Typeobservacao.php

Contents of the model:

App::uses('AppModel', 'Model');

class TiposObservacao extends AppModel {

    public $useTable = 'tipos_observacoes';
    public $primaryKey = 'tipo_observacao_id';

   public $hasMany = array(
     "Observacao" => array(
              'className' => 'Atendimento.Observacao',
              'foreignKey' => 'tipo_observacao_id',
            )
   );

}

1 answer

1


If your controller associated with this model is called "Typosobservacaos", obeying the established naming convention, then Cake should recognize without problem.

If the model is used in any other controller, use the $uses attribute:

class QualquerController extends AppController
{
     public $uses = array('TiposObservacao');
}

This way, Cake will instantiate the model for you in the variable $Typeremarks

$this->TiposObservacao->find();
  • Yesterday, after so much breaking my head, I discovered that I was sinning in a stupid detail: on loadModel, I forgot to put the name of the Plugin before the name of the Model. Anyway, thank you very much.

  • Note: loadModel is used "on the fly", to only set the correct model use the $uses, as suggested.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.