I have created a simple class inside my bundle in Symfony 2:
class MyTest {
public function myFunction() {
$logger = $this->get( logger );
$logger->err( testing out );
}
}
如何进入集装箱?
I have created a simple class inside my bundle in Symfony 2:
class MyTest {
public function myFunction() {
$logger = $this->get( logger );
$logger->err( testing out );
}
}
如何进入集装箱?
你们需要注入服务集装箱。 你的班子将研究:
use SymfonyComponentDependencyInjectionContainerInterface;
class MyTest
{
private $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function myFunction()
{
$logger = $this->container->get( logger );
$logger->err( testing out );
}
}
然后在控制器或集装箱内 意识到:
$myinstance = new MyTest($this->container);
如果需要更多的解释:。
在大多数情况下,对整个集装箱进行拦截是坏的。 单独拒绝所需服务。
namespace Vendor;
use SymfonyComponentHttpKernelLogLoggerInterface;
class MyTest
{
private $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function myFunction()
{
$logger->err( testing out );
}
}
登记<代码>服务:yml:
services:
my_test:
class: VendorMyTest
arguments: [@logger]
为什么不添加<条码>@logger 只是服务? e.g
arguments: [@logger]
如果你想添加集装箱(WHICH IS NOT RecommendationsED),那么你可以在<代码>@service_container上添加<条码>。
I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...
<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...
I found this script online that creates a thumbnail out of a image but the thumbnail image is created with poor quality how can I improve the quality of the image. And is there a better way to create ...
如何确认来自正确来源的数字。
Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...
I wonder there is a way to post a message to a facebook business page with cURL? thanks
I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...
How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...