A
A
Alexander Mikhailenko2018-05-31 15:15:37
Slim Framework
Alexander Mikhailenko, 2018-05-31 15:15:37

Why are classes from $container dependencies not visible in Slim Framework?

Good afternoon, please tell me what could be the reason where to look at least.
I use Slim php framework, I add my two classes in the dependency file

$container['excel'] = function () {
    $excel = new \PhpOffice\PhpSpreadsheet\Spreadsheet;

    return $excel;
};
$container['xls'] = function () {
    $xls = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx;
    return $xls;
};

but when you try to access them in the router using $this, php storm does not even pull up the class itself, respectively
$app->get('/test', function (Request $request, Response $response, array $args) {
    $this->и тут автокомплит не работает

});

no autocomplete of methods. although right in the dependency file it works.
Where to dig, what could be the problem:

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arman, 2018-05-31
@m1hasik

Probably php storm is not so smart, they usually put additional plugins for one or another framework.
I usually specify in a variable and php-doc:

/**
 * @var $xls \PhpOffice\PhpSpreadsheet\Writer\Xlsx
 */
$xls = $this->xls;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question