Blesta Addons Posted August 24, 2018 Report Posted August 24, 2018 what is the best way to initialize the Logger Model outside the models? is the logger available in the container Class?
Tyson Posted August 24, 2018 Report Posted August 24, 2018 <?php use Blesta\Core\Util\Common\Traits\Container; class MyClass { use Container; public function myMethod() { if (($logger = $this->getFromContainer('logger'))) { $logger->info('The Logger is loaded'); } } } Michael 1
Blesta Addons Posted August 25, 2018 Author Report Posted August 25, 2018 On 8/24/2018 at 9:36 PM, Tyson said: <?php use Blesta\Core\Util\Common\Traits\Container; class MyClass { use Container; public function myMethod() { if (($logger = $this->getFromContainer('logger'))) { $logger->info('The Logger is loaded'); } } } Expand i think this for blesta 4.3 and above ?
Tyson Posted August 27, 2018 Report Posted August 27, 2018 On 8/25/2018 at 2:03 PM, Blesta Addons said: i think this for blesta 4.3 and above ? Expand Yes, that's correct.
Blesta Addons Posted August 28, 2018 Author Report Posted August 28, 2018 On 8/27/2018 at 11:49 PM, Tyson said: Yes, that's correct. Expand getFromContainer() only work in models or controllers, it give us a error when we call it from a abstract class that is not model/controller/helper/components .
Tyson Posted August 28, 2018 Report Posted August 28, 2018 Did you load the Container trait as shown in my example? That should work just fine. Models and controllers can call getFromContainer because they inherit from AppController/AppModel, which uses the Container trait.
Blesta Addons Posted August 28, 2018 Author Report Posted August 28, 2018 On 8/28/2018 at 4:16 PM, Tyson said: Did you load the Container trait as shown in my example? That should work just fine. Models and controllers can call getFromContainer because they inherit from AppController/AppModel, which uses the Container trait. Expand i have used the monolog directly. but even if i will test again your solution and give reply, it might help other in the future .
Blesta Addons Posted August 30, 2018 Author Report Posted August 30, 2018 On 8/28/2018 at 4:16 PM, Tyson said: Did you load the Container trait as shown in my example? That should work just fine. Expand i have made a simple test and it worked .
Blesta Addons Posted September 25, 2018 Author Report Posted September 25, 2018 another solution if (($container = Configure::get('container'))) { $logger = $container->get('logger'); $logger->info('this is me'); }
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now