Good morning
How Can I use $settings $logger and $db in __construct from the $container in dependencies.php in a Model function in a Slim Api?
I have the following setup for my Slim framework Api:
settings.php (has $settings $looger and $db in $container)
/src/Models/DataModel.php
namespace Namespace\Api\Models\v1;
class DataModel
{
private $settings;
private $logger;
private $db;
function __construct($settings, $logger, $db) {
$this->settings = $settings;
$this->logger = $logger;
$this->db = $db;
}
function get() {
****
}
}
routes.php
use Slim\Http\Request;
use Slim\Http\Response;
$app->group('/v1', function () use ($app) {
$app->GET('/imprint/[{id}]', 'Namespace\Api\Models\v1\DataModel:get');
});
The Error Message I get is:
Too few arguments to function eRecht24\Api\Models\v1\ImprintModel::__construct()
If I understand correctly I need to instantiate the model like so in order to pass $settings $logger and $db:
$model = new Namespace\Api\Models\v1\DataModel($container->settings, $container->logger, $container->db);
As far as I can tell they ($container->settings etc.) are not resolving however. Is this instantiation correct and where do I put it in order to be able to use $settings $logger and $db in my Model functions?