Cakephp使用模型而不定义模型文件

I am new to cakephp and trying to customise a cake application.

I have seen they are using models without having model class files in app/models folder

I think there is an automatic mapping from table to model

I am sharing some usefull lines of codes

    public $uses = array('LinkEmperorCampaignDetail','Configuration','Article');

        $this->paginate = array(
            'conditions' => $condition,
            'limit' => 10
        );

        $this->set('articles', $this->paginate('Article'));

As you have seen its importing Article model using $uses variable, there is a table "articles" in database, But there is no file Article.php in app/models. I have deleted cache folder and disabled caching.

I have checked if it is automatic, by creating a table "test" and used this code

  $test=$this->test->find('all');;
  var_dump($test);exit();

but getting this error Error: Call to a member function find() on a non-object

Please let me know how this is happening

Thanks, Lajeesh

Change it to:

 $test = $this->Test->find('all');

Also, please, check cakephp model and database conventions

Model files are optional

Cake will user an AppModel instance if there is no model file found:

CakePHP will dynamically create a model object for you if it cannot find a corresponding file in /app/Model.

As such a reference tothis->Article will be an instance of AppModel as the model is declared in the $uses variable but a model file doesn't exist.

That doesn't mean $this->RandomModel works

Referencing a random model, as seen in the question, will simply produce the following error:

Call to a member function find() on a non-object

That's to be expected because the controller knows nothing about the Test model from the code in the question.

The optional model file handling does not mean that you can reference any model by expecting it to exist as a Controller class property. $uses exists for the purpose of telling the controller which models it needs to know about. If a model is only needed in specific circumstances, loadModel exists for this purpose:

$this->loadModel('Test');
$stuff = $this->Test->find('all');