How to get an array of data on the Success page in Symfony 1.4

I am fetching data from a database in Symfony 1.4.

The problem is that I cannot access this array in the Success page using a loop foreach

and print_r()

.

Mistake

Warning. Invalid argument for foreach ().

But when I do the same on the Action page after the Query has been executed, I can get the data using foreach()

and print_r($result)

.

Why can't I get this array on the success page?

The request and loop I'm using is below:

$birthSearchQuery = Doctrine_Query::create()->select('a.bir_le_reg,a.bir_le_dob,b.bir_le_district')
            ->from('BirthLegalInfo as a')
            ->innerJoin('a.BirthStatisticalInfo as b')
            ->Where('bir_le_reg_no IS NOT NULL')
            ->andwhere('bir_le_birth_state =' . $birthState)
            ->andwhere('bir_le_birth_district =' . $birthDistrict)
            ->andwhere('YEAR(bir_le_dob)=' .$birthFromYear);

      $result = $birthSearchQuery->execute(array(), Doctrine::HYDRATE_SCALAR);

      

It returns me an array of arrays using print_r($result)

like this

Array
    (
 [0] => Array
    (
        [bir_le_reg] => Delhi
        [bir_le_district] => Delhi
        [bir_le_dob] => 2015
    )

[1] => Array
    (
        [bir_le_reg] => Delhi
        [bir_le_district] => Delhi
        [bir_le_dob] => 2014
    )

[2] => Array
    (
        [bir_le_reg] => Delhi
        [bir_le_district] => Delhi
        [bir_le_dob] => 2015
    )
)

      

I am using foreach loop like

foreach($result as $value){
    echo $value['bir_le_district'];
    echo '<br />';
    echo $value['bir_le_reg'];
    echo '<br />';
    echo $value['bir_le_dob'];
}

      

+3


source to share


1 answer


To pass a variable to a template in symfony 1.x, you must prefix it $this->

.

In your case, you should do this:

$this->result = $birthSearchQuery->execute(array(), Doctrine::HYDRATE_SCALAR);

      



Then, in the template, you can call:

foreach ($result as $value) {

      

No problem.

+2


source







All Articles