Reputation: 433
My code of Helper Class is as below :
public function getPlaceholders()
{
try {
echo $this->getParameter('kernel.root_dir');
} catch (ParseException $e) {
printf("Unable to parse the YAML string: %s", $e->getMessage());
}
return $this->placeholders;
}
It's returning the error as below :
Attempted to call an undefined method named "getParameter" of class "AppBundle\Helper\Placeholders".
Please advice me on it.
Upvotes: 0
Views: 571
Reputation: 36924
Inject the container
services:
app.helper.placeholders:
class: AppBundle\Helper\Placeholders
arguments: ['@service_container']
And use the container's accessor methods for parameters:
namespace AppBundle\Helper;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Placeholders
{
private $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function getPlaceholders()
{
$root_dir = $this->container->getParameter('kernel.root_dir');
// ...
Upvotes: 1