Welcome Guest, Not a member yet? Register   Sign In
I'm having trouble with flashdata
#1

[eluser]insub2[/eluser]
I'm trying to pass an array of search results using flashdata but it's not working.

I have tried a string and different array. Both worked.

Code:
$resultsArray = $this->search->search($searchqueryStr, $near);

/*Both of these Worked
$resultsArray = 'string';
$resultsArray = array(    '1' => 'one',
                '2' => 'two',
                '3' => 'three',
                'array' => array (    'food' => 'pizza',
                            'god' => 'null',
                            'ddUrl' => 'http://www.google.com/maps?source=uds&daddr=155+Michigan+St+NW,+Grand+Rapids,+MI+(Grand+Rapids+Press)[email protected],-85.67034&saddr=42.9704710,-85.6686480'
                        ),
                'class' => 'l'
            );
*/

$this->db_session->set_flashdata('resultsArray', $resultsArray);

$empty = (empty($resultsArray))? 'empty' : 'not empty';
echo $empty.'!<br>';
echo '<pre>';
$flash = $this->db_session->flashdata('resultsArray');
$tryTry = (empty($flash))? 'flash is empty' : 'flash is full';
die ($tryTry.' - '.print_r($flash));

About the db_session, I'm using FreakAuth_Lite and if load the session's library, FAL freaks out.

Is there a size limit to flashdata?

UPDATE:
Using userdata instead of flashdata seems to work. But I'm still curious if there is a size limit or if there is some other reason for it not working.
#2

[eluser]TheFuzzy0ne[/eluser]
Flashdata is only available to the next request, not the request that it was set.
#3

[eluser]insub2[/eluser]
So, this works:

Code:
...


        $resultsArray = $this->search->search($searchqueryStr, $near);
        $this->db_session->set_userdata('resultsArray', $resultsArray);
        die(print_r($this->db_session->userdata('resultsArray'));
        redirect('google/searchresults');
    }
}

function searchresults($searchquery = FALSE, $near = FALSE, $page = FALSE, $sort = FALSE)
{

...

HOWEVER! This doesn't work.
Code:
...


        $resultsArray = $this->search->search($searchqueryStr, $near);
        $this->db_session->set_userdata('resultsArray', $resultsArray);
        redirect('google/searchresults');
    }
}

function searchresults($searchquery = FALSE, $near = FALSE, $page = FALSE, $sort = FALSE)
{
    $resultsArray = $this->db_session->userdata('resultsArray');
    die(print_r($resultsArray));

...

Does any one have any idea why?
#4

[eluser]TheFuzzy0ne[/eluser]
How big is the array you're trying to store?

Does it contain any backslashes?

Are you sure you have cookies enabled in your browser?

Are you sure you have configured your cookies correctly?
#5

[eluser]Italo Domingues[/eluser]
Session of the Codeigniter is not native, ie $_SESSION, it uses cookies, and cookies have a limit yes.
#6

[eluser]insub2[/eluser]
[quote author="TheFuzzy0ne" date="1237698934"]Flashdata is only available to the next request, not the request that it was set.[/quote]

But but ... it worked when there was just a string ('string') and the other array.

[quote author="TheFuzzy0ne" date="1237699553"]How big is the array you're trying to store?

Does it contain any backslashes?

Are you sure you have cookies enabled in your browser?

Are you sure you have configured your cookies correctly?[/quote]

Backslashes? IDK.

Cookies enabled? Yes, FreakAuth_Lite works and, I believe, that it is using the same db_session library.

No, I am not sure I have cookies configured correctly.

The db_session data is returned while in the same control. But it is lost after the redirect. I've checked the database ci_sessions table and there appears to be some data stored for 'resultsArray' ...though there also seems to be a lot of weird markup that I don't recognize (stuff like "a:1" and "s:3").

Is there a way to check the size of a variable? Something like measure($var) ?
#7

[eluser]TheFuzzy0ne[/eluser]
Please post all of the code for your controller, or at least the two functions where you are trying to pass the flashdata across. I believe there is a misunderstanding somewhere, which can be sorted easily.
#8

[eluser]insub2[/eluser]
OK, here are the two scenarios we are working with. Firstly, in both I'm using userdata instead of flashdata. I get the same results whether I'm using CodeIgniter's Session Library or FreakAuth_Lite's DB_Session's Library. In the first, I have set the userdata, recall it and assign it to variable ($pizza) then die and print in the same controller. That returns the expected output. In the second, I set the userdata, redirect to another controller then assign it to variable ($pizza), die and print. That doesn't output as expected.

HOWEVER! It does work with a simples string and smaller array. I'm betting it's just too damn large and I'll have to work out something else. BUT I would like to know if there is anyway to measure a variable's data?

Scenario 1 Code:
Code:
// --------------------------------------------------------------------- //
// ------------------------------[SEARCH]------------------------------- //
// --------------------------------------------------------------------- //
function search($searchquery = FALSE, $near = FALSE)
{
    if ($searchquery && $near)
    {
        $_POST['searchquery'] = $searchquery;
        $_POST['near'] = $near;
    }
    
    //Set rules for Search Inputs.
    $this->form_validation->set_rules('near', 'Location', 'trim|required|callback__coords');
    $this->form_validation->set_rules('searchquery', 'Search Term', 'trim|required');
    
    //Run form validation and check for errors.
    //
    //ERRORS: re-display and re-populate the Search Form.
    if ($this->form_validation->run() == FALSE)
    {
        $data['title'] = 'Google Search';
        $data['layout'] = 'google_search_layout'; // pass the layout view to use as a parameter
        $this->load->view($this->_container,$data);
    }
    else
    {
        //Use Search Model to perform search and receive Results Array.
        $searchqueryStr = set_value('searchquery');
        $near = set_value('near');
        $resultsArray = $this->search->search($searchqueryStr, $near);
        $this->session->set_userdata('resultsArray', $resultsArray);
        echo '<h1>Search Controller</h1><pre>';
        $pizza = $this->session->userdata('resultsArray');
        die(print_r($pizza));
        redirect('google/results');
    }
}

function results()
{
    $pizza = $this->session->userdata('resultsArray');
    echo '<h1>Results Controller</h1><pre>';
    die(print_r($pizza));
}

Scenario 1 Output:
Quote:Search Controller

Array
(
[queryStr] => airport
[near] => grand rapids mi
[returnedBusinesses] => Array
(
[0] => Array (
[GsearchResultClass] => GlocalSearch
[viewportmode] => computed
[listingType] => local
[lat] => 42.957713
[lng] => -85.673378
[accuracy] => 8
[title] => Business Transportation Services
[titleNoFormatting] => Business Transportation Services
[ddUrl] => http://www.google.com/maps?source=uds&da...85.6686480

***There is a lot more***
***And so on for 32(+) returnedBusinesses***


Scenario 2 Code:
Code:
// --------------------------------------------------------------------- //
// ------------------------------[SEARCH]------------------------------- //
// --------------------------------------------------------------------- //
function search($searchquery = FALSE, $near = FALSE)
{
    if ($searchquery && $near)
    {
        $_POST['searchquery'] = $searchquery;
        $_POST['near'] = $near;
    }
    
    //TEMP
    $page = 1;
    
    
    //Set rules for Search Inputs.
    $this->form_validation->set_rules('near', 'Location', 'trim|required|callback__coords');
    $this->form_validation->set_rules('searchquery', 'Search Term', 'trim|required');
    
    //Run form validation and check for errors.
    //
    //ERRORS: re-display and re-populate the Search Form.
    if ($this->form_validation->run() == FALSE)
    {
        $data['title'] = 'Google Search';
        $data['layout'] = 'google_search_layout'; // pass the layout view to use as a parameter
        $this->load->view($this->_container,$data);
    }
    else
    {
        //Use Search Model to perform search and recieve Reuslts Array.
        $searchqueryStr = set_value('searchquery');
        $near = set_value('near');
        $resultsArray = $this->search->search($searchqueryStr, $near);
        $this->session->set_userdata('resultsArray', $resultsArray);
        //echo '<h1>Search Controller</h1><pre>';
        //$pizza = $this->session->userdata('resultsArray');
        //die(print_r($pizza));
        redirect('google/results');
    }
}

function results()
{
    $pizza = $this->session->userdata('resultsArray');
    echo '<h1>Results Controller</h1><pre>';
    die(print_r($pizza));
}

Scenario 2 Output:
Quote:Results Controller

1
#9

[eluser]TheFuzzy0ne[/eluser]
You're right. I also think you're trying to store too much data, and it might be time to rethink your approach. I'm not sure why you need to pass all of that data over to the next request. Can you not do it with the IDs for the businesses, and then load them from the database before displaying them?
#10

[eluser]insub2[/eluser]
[quote author="TheFuzzy0ne" date="1237829557"]You're right. I also think you're trying to store too much data, and it might be time to rethink your approach. I'm not sure why you need to pass all of that data over to the next request. Can you not do it with the IDs for the businesses, and then load them from the database before displaying them?[/quote]

Yeah, I cam to the same conclusion. The reason I was passing that is because I was combining results from Google Local Search and a search on our database. But with a little rework, I can just store the ID. Thanks for the help!




Theme © iAndrew 2016 - Forum software by © MyBB