Welcome Guest, Not a member yet? Register   Sign In
Adding data in stdClass array before send it to the view
#1

[eluser]Unknown[/eluser]
Hello all,

I would like to add additional data before the sending to the view.

Currently, I'am sending data to the view classically :
Code:
$data['members'] = $this->Membres_mod->getMembers();
$this->load->view('view_myview', $data);

In the view, it gives :

Code:
[0] => stdClass Object
(
    [id] => 1
    [firstname] => Franck
    [lastname] => Dupont
)
[1] => stdClass Object
(
    [id] => 2
    [firstname] => Marc
    [lastname] => Carrez
)

I would like to add data in the array before send it to the view (data that can't be retrieved by SQL join), for example :

Code:
[0] => stdClass Object
(
    [id] => 1
    [firstname] => Franck
    [lastname] => Dupont
    [nb_contributions] => 24 // Additional data
)
[1] => stdClass Object
(
    [id] => 2
    [firstname] => Marc
    [lastname] => Carrez
    [nb_contributions] => 38 // Additional data
)

I'm surprised that "stdClass" objects don't dispose of "Push" method for add data properly.

What's the best way to add data to my "stdClass" object in the controller before send it to the view ?

Thank you !

Sorry for my english...

Franck.
#2

[eluser]WanWizard[/eluser]
Code:
$data['members'][0]->nb_contributions = 24;
#3

[eluser]Unknown[/eluser]
Thank you very much WanWizard.




Theme © iAndrew 2016 - Forum software by © MyBB