This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

Setting parameters from Database

About symfony tutorials, symfony book and API documentation.

Setting parameters from Database

by shairyar » Wed Feb 25, 2015 12:37 pm

Hi,

Instead of hard coding the parameters in parameters.yml I am trying to load them from database. Not all parameters in parameters.yml needs to be loaded from database just a few, like api details of paypal

I came across this documtation http://symfony.com/doc/current/cookbook/configuration/external_parameters.html#miscellaneous-configuration but it does not really help.

This is what I have done so far to load some data in config.yml from database

In config.yml I have imported the parameters.php

Code: Select all
imports:
    - { resource: parameters.php }


If I add static information in parameters.php like the one below it works fine

Code: Select all
$demoName = 'First Last';
$container->setParameter('demoName', $demoName);


However I am not able to fetch information from database table. I thought i should create class and make use of
Code: Select all
$em = this->getDoctrine()->getManager();
and it should work but it doesn't and i get the error of

Code: Select all
Notice: Undefined variable: paypal_data in /opt/lampp/htdocs/services/app/config/parameters.php (which is being imported from "/opt/lampp/htdocs/services/app/config/config.yml").


This is the attempt i made but the code does not seem to go in __construct()

Code: Select all
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\ORM\Mapping as ORM;

class parameters extends Controller
{
    public $paypal_data;

    function __construct() {
        $this->indexAction();
    }

    public function indexAction(){

        $em = $this->getDoctrine()->getManager();
        $this->paypal_data = $em->getRepository('featureBundle:paymentGateways')->findAll();

    }

}
$demoName = 'First Last';
$container->setParameter('demoName', $demoName);
$container->setParameter('paypal_data', $this->paypal_data);


Any help will be much appreciated.
shairyar
Junior Member
 
Posts: 1
Joined: Wed Feb 25, 2015 12:29 pm