0

我问这个的原因是我对我想传递给下一个视图的一个愚蠢的小消息感到生气。所以如果我这样做:

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');
        }

它工作得很好,但如果我这样做:

    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');
    }

它不起作用。

我在这里以 main/form 显示 falshdata:

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

您可以猜到我正在尝试将 Payal 的错误消息拉到视图中以进行错误处理。谢谢

4

2 回答 2

2

在 Codeigniter 中,整个会话数据的一般大小是有限的,是的。这也包括闪存消息。

这是因为默认情况下它适用于 cookie,并且 cookie 的大小有限。

防止这种情况的简单方法是使用基于数据库的会话或 PHP 本机会话适配器之一。

于 2012-08-05T22:08:13.073 回答
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

于 2012-08-06T09:29:33.817 回答