CI Objects and arrays - aaghh! - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: CI Objects and arrays - aaghh! (/showthread.php?tid=31759) |
CI Objects and arrays - aaghh! - El Forum - 06-30-2010 [eluser]Loquela[/eluser] I think I'm missing the wood for the trees here. I'm struggling with retrieving values for arrays and objects. Please help. In my controller I have: Code: $data = array('upload_data' => $this->upload->data()); and I am able to list the upload_data using a loop: Code: foreach($upload_data as $item => $value):, etc, etc This works fine. But what I can't seem to do is capture $orig_name from the $upload_data variable for my model. I'm doing this: controller: Code: $this->files_model->insert_file($data); model: Code: function insert_file($data) Could anyone help? Many thanks in advance, L. CI Objects and arrays - aaghh! - El Forum - 06-30-2010 [eluser]Simian Studios[/eluser] The way the view handles data and the way the model handles data are different. The view automatically parses the $data array into simple variables for use, whereas the model doesn't. If you pass $data['upload_data'] to your model instead of the whole $data array, it should work. CI Objects and arrays - aaghh! - El Forum - 06-30-2010 [eluser]Loquela[/eluser] Thanks for this Simian, Do you mean model: Code: function insert_file($data['upload_data']) This produces a "Parse error: parse error, expecting `')'" L. CI Objects and arrays - aaghh! - El Forum - 06-30-2010 [eluser]Simian Studios[/eluser] [quote author="Loquela" date="1277931804"] Do you mean: Code: function insert_file($data['upload_data']) Not quite.. in the controller: Code: $this->files_model->insert_file($data['upload_data']); And then make sure in the model that you are referencing the correct variable. E.g. Code: function insert_file($data) CI Objects and arrays - aaghh! - El Forum - 06-30-2010 [eluser]Hernando[/eluser] $this->files_model->insert_file($data['upload_data']); [quote author="Loquela" date="1277931804"]Thanks for this Simian, Do you mean model: Code: function insert_file($data['upload_data']) This produces a "Parse error: parse error, expecting `')'" L.[/quote] CI Objects and arrays - aaghh! - El Forum - 07-01-2010 [eluser]Loquela[/eluser] Thanks Simian, Sorted! L. CI Objects and arrays - aaghh! - El Forum - 07-01-2010 [eluser]Simian Studios[/eluser] [quote author="Loquela" date="1277990273"]Thanks Simian, Sorted! L.[/quote] Cool, no worries Thanks for the blog comment too, have corrected the post now CI Objects and arrays - aaghh! - El Forum - 07-01-2010 [eluser]Loquela[/eluser] :coolsmile: Sharp! |