简体   繁体   中英

Slim3 DI container access diferrence

$app->get('......',....)
$container=$this->getContainer();

Is there any difference between the following? Pimple docs uses the former while slim examples the latter. Is any of the two considered more formal in PSR terms?

    $server=$container['App\Model\Server'];

    $server=$container->get('App\Model\Server');

Slims Container implements the Interop/ContainerInterface , whereas Pimple does not. The Interop/ContainerInterface requires the container to have two methods: get() and has() . get() throws an exception ( NotFoundException ) when an entry is not found. With plain Pimple you only get a notice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM