Blesta Addons Posted August 24, 2018 Report Share 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? Quote Link to comment Share on other sites More sharing options...
Tyson Posted August 24, 2018 Report Share 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 Quote Link to comment Share on other sites More sharing options...
Blesta Addons Posted August 25, 2018 Author Report Share Posted August 25, 2018 16 hours ago, 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'); } } } i think this for blesta 4.3 and above ? Quote Link to comment Share on other sites More sharing options...
Tyson Posted August 27, 2018 Report Share Posted August 27, 2018 On 8/25/2018 at 7:03 AM, Blesta Addons said: i think this for blesta 4.3 and above ? Yes, that's correct. Quote Link to comment Share on other sites More sharing options...
Blesta Addons Posted August 28, 2018 Author Report Share Posted August 28, 2018 14 minutes ago, Tyson said: Yes, that's correct. 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 . Quote Link to comment Share on other sites More sharing options...
Tyson Posted August 28, 2018 Report Share 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. Quote Link to comment Share on other sites More sharing options...
Blesta Addons Posted August 28, 2018 Author Report Share Posted August 28, 2018 3 hours ago, 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. 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 . Quote Link to comment Share on other sites More sharing options...
Blesta Addons Posted August 30, 2018 Author Report Share Posted August 30, 2018 On 8/28/2018 at 5:16 PM, Tyson said: Did you load the Container trait as shown in my example? That should work just fine. i have made a simple test and it worked . Quote Link to comment Share on other sites More sharing options...
Blesta Addons Posted September 25, 2018 Author Report Share Posted September 25, 2018 another solution if (($container = Configure::get('container'))) { $logger = $container->get('logger'); $logger->info('this is me'); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.