[eluser]sauronlord[/eluser]
[quote author="jedd" date="1259993403"][quote author="sauronlord" date="1259972052"]
I am new to Code Igniter, and I am curious how to pass a lot/complex data to another controller.
[/quote]
Hi sauronlord. I think, from this question, that you perhaps need to re-think your application design. Do you mean
from one controller here, to another controller? If so, there are probably more elegant ways to do what you're trying to do.
You certainly don't want to pass 'hundreds of items' through the URL, let alone try to reconstruct a 2-D array from that.
Post data might work, but it seems a little excessive. If it's a form you're submitting, then post data is obviously the right way of doing this - but if you just want to save state between sessions .. well .. there are other ways.
If your session data is kept in a cookie, you have 4KB (or less) to play with. If they're stored in a database, you have whatever the limit is on your default TEXT column size (assuming you used the code described in the Session page) for your database type.
Quote:Is there a way to make objects persist between page transitions?
serialize and store - ideally in the DB, as file system is likely to be slower, plus there's overhead when you start creating unique filenames.
I still think that your design needs a revisit if you find you need to recover a Foo object on every page load.[/quote]
Thanks for the advice.
I really just want an *easy* way of getting at an NxM (associative) matrix.
I use a DB to populate things, however I want to find out what changed in the previous spreadsheet and then do the update of the objects.
Can I get something like this: (pseudo code):
class MyForm extends Controller
{
$m_InitialDataGrid[][]; Associative array of rows mapping to another array(field => value)
$m_DataGrid[][]; // (Updated) Associative array of rows mapping to another array(field => value)
// Draw the HTML and populate the grid with default data from DB
public RenderScreen()
{
LoadGridFromDB($m_InitialDataGrid);
$m_DataGrid = $m_InitialDataGrid;
populateTemplate("myTemplate.tpl", $m_DataGrid);
}
// When the user clicks 'save' on the page
// I want to get at the updated values in $m_DataGrid;
public SavePressed()
{
// Loop through all elements in $m_DataGrid and compare each row to $m_InitialDataGrid
// And only commit to DB the elements that are different
}
};
Now let's say there is another method that will send the changed data to another page.
So I would like to populate some "datagrid object" and pass it over to the other page.
In particular, I do not want to have to deal with decoding the NxM array through POST vars directly, but would prefer some helper utilities to get this data across to another page.
Is it possible to serialize an object and save it to $_POST['MYOBJECT'];
And then retrieve it in another Controller like this:
if (isset($_POST['MYOBJECT']))
{
$dataGrid = new DataGrid($_POST['MYOBJECT']]);
}
Thanks for your help,