Welcome Guest, Not a member yet? Register   Sign In
CI Objects and arrays - aaghh!
#1

[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)
     {
      
           $this->db->insert('als_files', array('file_filename' => $upload_data['orig_name']));
     }
I know this is wrong and opf course i get "Undefined variable: upload_data"

Could anyone help?

Many thanks in advance,

L.
#2

[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.
#3

[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.
#4

[eluser]Simian Studios[/eluser]
[quote author="Loquela" date="1277931804"]
Do you mean:
Code:
function insert_file($data['upload_data'])
[/quote]

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)
{    
    $this->db->insert('als_files', array('file_filename' => $data['orig_name']));
}
#5

[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]
#6

[eluser]Loquela[/eluser]
Thanks Simian,

Sorted!

L.
#7

[eluser]Simian Studios[/eluser]
[quote author="Loquela" date="1277990273"]Thanks Simian,

Sorted!

L.[/quote]

Cool, no worries Smile Thanks for the blog comment too, have corrected the post now Wink
#8

[eluser]Loquela[/eluser]
:coolsmile:

Sharp!




Theme © iAndrew 2016 - Forum software by © MyBB