Is there a maximum length in Codeigniter falshdata?

强颜欢笑 提交于 2019-12-25 05:31:40

问题


The reason why I'm asking that is I'm becoming mad about a small stupid message I'd like to pass to the next view. So if I do :

if(!$this->paypal_pro->APICallSuccessful($PayPalResult['ACK']))
        {
            var_dump($PayPalResult['ERRORS']);
            $message=array();
            foreach ($PayPalResult['ERRORS'] as $row => $error){
                // $message['flashError'][$row]['L_SHORTMESSAGE'] = $error['L_SHORTMESSAGE'];
                $message['flashError'][$row]['test'] = "The Session class permits you maintain a user's";
                // $message['flashError'][$row]['L_ERRORCODE'] = $error['L_ERRORCODE'];
                // $message['flashError'][$row]['L_LONGMESSAGE'] = $error['L_LONGMESSAGE'];
            }
            // print_r($message);
            $this->session->set_flashdata($message);

            redirect('main/Form');
        }

It works great, but if I do :

    if(!$this->paypal_pro->APICallSuccessful($PayPalResult['ACK']))
    {
        var_dump($PayPalResult['ERRORS']);
        $message=array();
        foreach ($PayPalResult['ERRORS'] as $row => $error){
            // $message['flashError'][$row]['L_SHORTMESSAGE'] = $error['L_SHORTMESSAGE'];
            $message['flashError'][$row]['test'] = "The Session class permits you maintain a user's  and track their activity while";
            // $message['flashError'][$row]['L_ERRORCODE'] = $error['L_ERRORCODE'];
            // $message['flashError'][$row]['L_LONGMESSAGE'] = $error['L_LONGMESSAGE'];
        }
        // print_r($message);
        $this->session->set_flashdata($message);

        redirect('main/Form');
    }

It doesn't work.

I'm showing the falshdata here, in main/form :

<?php if($this->session->flashdata('flashError')):?>
        <div class='flashError'>
    <?php   
        print_r($this->session->flashdata('flashError'));
    ?>
        </div>
    <?php endif?>

You can guess I'm trying to pull the error messages of Payal to the view for my errors Handling. Thanks


回答1:


I had lots of issues with sessions (which are essentially cookies by default in Codeigniter unless you store in the db). The session size (or cookie size) depends on the browser but I think the norm is around 3k - so won't handle what you are proposing to do.

I wasn't so sure about storing the session details in the db, so added the native sessions library and it has been much easier (and less buggy). You can still use the CI flashdata feature with this library (as well as set session data like $this->session->set_userdata('foo', $foo), but it allows you to use sessions just like you were using native PHP i.e. you can print_r($_SESSION) - which I don't think you can do with default session features in CI.

Here's a post with some more information: CodeIgniter sessions vs PHP sessions




回答2:


In Codeigniter, the general size of the whole session data is limited, yes. That includes the flash messages as well.

This is because by default it works with cookies and cookies are of limited size.

The easy way to prevent that is to use database based sessions or one of the PHP native session adapters.



来源:https://stackoverflow.com/questions/11820345/is-there-a-maximum-length-in-codeigniter-falshdata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!