I am playing with yii container. Actually I am defining services in
config/web.php
file:
$container = Yii::$container;
$container->set('my_service', '\app\services\ServiceName');
I can call services correctly form controllers:
class SiteController
extends Controller
{
public function actionIndex()
{
$value = Yii::$container->get('my_service')->getValue();
return $this->render(
'index', [
'value' => $value,
]
);
}
}
where my service is
<?php
namespace app\services;
class ServiceName
{
public function getValue()
{
return 42;
}
}