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? Quote
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 Quote
Blesta Addons Posted August 25, 2018 Author Report 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
Tyson Posted August 27, 2018 Report 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
Blesta Addons Posted August 28, 2018 Author Report 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
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. Quote
Blesta Addons Posted August 28, 2018 Author Report 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
Blesta Addons Posted August 30, 2018 Author Report 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
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'); } Quote
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.