How to load a model in a component correctly? So I can use this call:
$settings = $this->Settings->get(1);
Thank you
How to load a model in a component correctly? So I can use this call:
$settings = $this->Settings->get(1);
Thank you
You can always use TableRegistry::getTableLocator()->get('Settings')
from anywhere to get the Settings table.
I have annotation:
* @property \App\Model\Table\SettingsTable $Settings
* @method \App\Model\Entity\Setting[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = [])
And then how to make an annotation to tell me the columns?
This above works if I call this:
$settings = $this->Settings->get(1);
$settings->column
If I use your example, it doesn’t tell me the columns.
If you use Cake\Datasource\ModelAwareTrait;
, you’ll be able to use $this->loadModel('Settings')
. But autocomplete, while nice, isn’t the final arbitrator of what you can do. Up to you to decide whether that developer convenience is worth the extra code required for it.
Thank you, it works!