Welcome Guest, Not a member yet? Register   Sign In
Very weird array problem
#1

[eluser]frist44[/eluser]
I have created a few applications using some similar methods and found some issues with this particular one that I was never able to pinpoint. I have a view function that showing some information about an upload.

I do a check to see if info exists for that particular ID, and if it doesn't, redirect to a different page, which in turn shows some message based on flash data in the session library.

Code:
public function view($uploadid = FALSE) {
        
        // If not id is specified, go home
        if (!$uploadid) redirect(base_url());
        
        $data['upload'] = $this->uploads_model->get_upload($uploadid);
        
        // If not data is found with that ID, show error
        if (empty($data['upload'])) redirect_with_error(base_url(), 'flash_error_upload_view');
        
        $data['content_view'] = 'upload_view_view';
        $this->load->view('container_view', $data);        
    }

So when I first go to the page, everything looks normal, if I refresh the page, I get the error message showing as though the condition if (empty($data['upload'])) is satisfied however it doesn't do the redirection, just shows the message. That's the only place that message is referenced, so it has to be from that call.

Any idea????
#2

[eluser]vitoco[/eluser]
Code:
public function view($uploadid = FALSE) {
        
        // If not id is specified, go home
        if (!$uploadid)
        {
            // ONLY NEEDS SEGMENTS LIKE 'controller/method/param1.../'
            // http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html
            redirect('');
            // I THINK IT NEEDS AND exit() or return to stop the execution
            exit();
        }

        $data['upload'] = $this->uploads_model->get_upload($uploadid);
        
        // If not data is found with that ID, show error
        if (empty($data['upload']))
        {
            // SAME HERE I'LL GUESS
            redirect_with_error(base_url(), 'flash_error_upload_view'); // FIX THIS
            exit();
        }
        
        $data['content_view'] = 'upload_view_view';
        $this->load->view('container_view', $data);        
    }

Saludos
#3

[eluser]frist44[/eluser]
[quote author="vitoco" date="1271907971"]
Code:
public function view($uploadid = FALSE) {
        
        // If not id is specified, go home
        if (!$uploadid)
        {
            // ONLY NEEDS SEGMENTS LIKE 'controller/method/param1.../'
            // http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html
            redirect('');
            // I THINK IT NEEDS AND exit() or return to stop the execution
            exit();
        }

        $data['upload'] = $this->uploads_model->get_upload($uploadid);
        
        // If not data is found with that ID, show error
        if (empty($data['upload']))
        {
            // SAME HERE I'LL GUESS
            redirect_with_error(base_url(), 'flash_error_upload_view'); // FIX THIS
            exit();
        }
        
        $data['content_view'] = 'upload_view_view';
        $this->load->view('container_view', $data);        
    }

Saludos[/quote]

The functions are helpers that I have created that indeed take 2 arguments. Here is one:

Code:
if (!function_exists('redirect_with_error'))
{
    function redirect_with_error($url, $language_key, $txt = FALSE)
    {  
        $CI = &get;_instance();
        
        $msg = language($language_key) . ' ';
        $msg .= $txt ? $txt : '';
        
        $CI->session->set_flashdata('error', $msg);
        redirect($url);
    }
}

Also, the code doesn't need an exit because it's not even getting into that loop, or else the whole page would redirect. It has something to do with flash data being set outside of that conditional statement, but I'm baffled.
#4

[eluser]vitoco[/eluser]
there's an extra ; in the function
Code:
if (!function_exists('redirect_with_error'))
{
    function redirect_with_error($url, $language_key, $txt = FALSE)
    {  
        // ERROR => $CI = &get;_instance();
        $CI =& get_instance();
        
        $msg = language($language_key) . ' ';
        $msg .= $txt ? $txt : '';
        
        $CI->session->set_flashdata('error', $msg);
        redirect($url);
    }
}

i hope it works now

Saludos
#5

[eluser]frist44[/eluser]
[quote author="vitoco" date="1271988402"]there's an extra ; in the function
Code:
if (!function_exists('redirect_with_error'))
{
    function redirect_with_error($url, $language_key, $txt = FALSE)
    {  
        // ERROR => $CI = &get;_instance();
        $CI =& get_instance();
        
        $msg = language($language_key) . ' ';
        $msg .= $txt ? $txt : '';
        
        $CI->session->set_flashdata('error', $msg);
        redirect($url);
    }
}

i hope it works now

Saludos[/quote]

That was a copy/paste error. Keep in mind that nothing gives an error. The syntax is right, so looking for textual errors is probably not the best approach.
#6

[eluser]vitoco[/eluser]
[quote author="frist44" date="1271988531"]
That was a copy/paste error. Keep in mind that nothing gives an error. The syntax is right, so looking for textual errors is probably not the best approach.[/quote]

How do you get and extra ; in a copy paste ??? , well...i'll try to take other approach.

Saludos
#7

[eluser]Federico BaƱa[/eluser]
If the flash data is being set successfully the problem must be in the helper..

I'd try placing the redirect over the set_flashdata and check if setting the location header before the session works fine..




Theme © iAndrew 2016 - Forum software by © MyBB