Welcome Guest, Not a member yet? Register   Sign In
Storing multi dimensional arrays
#1

[eluser]drewjuk[/eluser]
Hi,

I am currently posting dynamic forms to my controller, but because I used ajax to load my page and I pass my values across in the url and use get on the actual controller which shows the page its posted to I can't pass my multi dimensional array across to the page which I need it to be on.

Is there a way to store it temporarily like in a session, I have looked into flash data apparently you cannot store it in here.

My array is posted on the first controller like this: $_POST['formarray']['formarray'], I need to some how store the contents which looks like this
Code:
Array ( [0] => Array ( [join1] => and [field1] => all [operators1] => is [string1] => second ) [1] => Array ( [join1] => and [field1] => all [operators1] => is [string1] => third ) [2] => Array ( [join1] => and [field1] => all [operators1] => is [string1] => forth ) )

Thanks, hope you can help
#2

[eluser]weboap[/eluser]
did you try to serialize() your array.
#3

[eluser]drewjuk[/eluser]
No what's that?
#4

[eluser]CroNiX[/eluser]
PHP.net documentation: Serialize()
#5

[eluser]drewjuk[/eluser]
Thanks, I did read it, I understand what it does, but would this be suitable to pass the serialized version over a url or would it be better to store it in flash data?

Thanks
#6

[eluser]CroNiX[/eluser]
Flashdata, or you will end up having to make a lot of characters that currently aren't allowed in the url be allowed, which can lower your security. You probably really don't want people to be able to read it anyway.
#7

[eluser]drewjuk[/eluser]
Yes that is true, I don't use any real values in the form values so even if they did try to inject anything it doesn't get outputted anywhere, just if $_GET['blah']==1 then do this etc...

Ok so I have tried to store it in flash data:

$bleh = serialize($_POST['formarray']['formarray']);
//print $bleh."<br/><br/>";
$this->session->set_flashdata('formarray', $bleh);
echo $this->session->flashdata('formarray');

but it does not seem to store anything, every time I call the flashdata back it seems to be empty, any idea what I am doing wrong?
#8

[eluser]CroNiX[/eluser]
Are you using the database for session storage or the default, cookie? If it's a cookie, you can't read it until the next page request as the cookie doesn't get sent until the current page gets sent to the browser.
#9

[eluser]weboap[/eluser]
can you post some code?
#10

[eluser]drewjuk[/eluser]
I use the database for sessions storage "ci_sessions" but there is no column for flash data in here, do I need to add something else?

I have had a look on wiki but cannot find anything of much help, I am guessing the information is not getting stored then in this case.

DO I need to add a config or library? I have not actually used flash data before, this is my first time with codeigniter.

Thanks for your help




Theme © iAndrew 2016 - Forum software by © MyBB