tiaguinho / mongodb-cakephp3

An Mongodb datasource for CakePHP 3.0
MIT License
28 stars 29 forks source link

Model, controller and query #16

Closed fehrenmann closed 7 years ago

fehrenmann commented 7 years ago

Hi Tiago

I am trying to use your plugin but i'm facing some issues with a simple find.

For example, I have a mongo table : markers As it is suggested in the readme, I created a MarkersTable php file, with the use Hayko\Mongodb\ORM\Table at the beginning of the file; But what about controller ? I wrote this lines in my Markers controller :

$this->loadmodel('Markers');
$marker = $this->Markers->find_markers($keyword);

where the find_markers function is in the MarkersTable php file :

public function find_markers ($keyword) {        
        $marker = $this->Markers->find('all', ['conditions' => ['name' => $keyword]]);
        return $marker;
    }

Do i have to load in my controller the table as i said below ? ($this->loadmodel('Markers'); ) It seems not cause i have an error (Unknown method "find_markers"...Could this be caused by using Auto-Tables ?)

Thanks by advance for your help and for your work

tiaguinho commented 7 years ago

You don't need to do that. Just use $this->Markers->find_markers(); inside your controller. Cakephp will handle the rest.

Cheers.