I'm trying to use FatFree and Cortex plugin within my REST API. I seem to have some challenges, at first I was challenged with the namespaces, which I was trying to find how to solve that. And then once I set that up, it was giving issues with method get() already existed. I later tried to not use namespaces to see if that would help, but continued with errors.
I am hoping to get some clarification on how to setup Cortex + F3 + REST API and having auto mapping routes. What am I doing wrong on setting up the model for Cortex? Namespaces doesn't really matter, if I use them or not (personally). Just would like it to work.
My Autoloader is
$f3->set('AUTOLOAD','app/controllers/;app/models/');
Multiple issues here.
\App\Controllers
, \App\Models
, etc. your AUTOLOAD setting should only be ''
to use the project root. If you set AUTOLOAD to app/
, then your namespace begins at this folder, so it's just namespace Controllers
. Same for Models\
to your namespace of other files, so within namespace \App\Controllers
in you must use new \App\Models\ContactsModel
.. if you only write new App\Models\ContactsModel
, it'll look for a file at app/controllers/app/models/contactsmodel.php
I would suggest:
app/Models
and app/Controller
, etcclass ContactsModel
-> ContactsModel.php
AUTOLOAD
to app/
onlynamespace Model;
and Contacts
-> namespace Controllers