Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am fetching data from datatabase in Symfony 1.4.

The problem is that i am not able to access that array in the Success page using foreach loop and print_r().

The error is

Warning: Invalid argument supplied for foreach().

But when I do same thing in the Action page after the Query is executed I am able to get the data using foreach() and print_r($result).

Why I am not able to get that array in the success page?

The query and the loop I am 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 is returning me a 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
    )
)

The foreach loop I am using is as

foreach($result as $value){
    echo $value['bir_le_district'];
    echo '<br />';
    echo $value['bir_le_reg'];
    echo '<br />';
    echo $value['bir_le_dob'];
}
like image 568
M.J Avatar asked Oct 19 '22 13:10

M.J


1 Answers

To pass a variable to the template in symfony 1.x you should prefix it by $this->.

In your case, you should do that:

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

Then, in your template, you can call:

foreach ($result as $value) {

Without any problem.

like image 164
j0k Avatar answered Nov 01 '22 11:11

j0k