简体   繁体   中英

Notice (8): Undefined offset: 2 [APP/View/Helper/CounterHelper.php

I am novice in cakephp and I use version 2.8, I would like to add a counter of visit on my homepage, nevertheless I obtain the following errors:

Notice (8): Undefined offset: 2 [APP/View/Helper/CounterHelper.php, line 157]
Notice (8): Undefined offset: 2 [APP/View/Helper/CounterHelper.php, line 186]

I put you the code end concerned:

 //Start get detail
        foreach ( $data as $value ){
            $temp = explode ("/", $value['Counter']['date_visit']);
            if ( $temp[0] == $this->Time['mday'] && $temp[1] == $this->Time['mon'] ){
                //Get user online
                if ( $newTime - $value['Counter']['time'] < $this->TimeOut )
                    ++$this->User_Online;
            }

  line 157 ====>  if ( $this->Time['year'] == $temp[2] ){

                //Get today static
                if ( $this_date == $temp[0] )
                    ++$this->Total_Today;

                //Get this month static
                if ( $this_month == $temp['1'] )
                    ++$this->Total_Month;
            }

        }

        //For previous

        $prev_date = $this->Time['mday'] - 1;
        $prev_mon = $this->Time['mon'] - 1;

        if ( $prev_date < 1){
            $prev_date = 30;
            $prev_mon -= 1;
        }

        if ( $prev_mon < 1)
            $prev_mon = 12;

        foreach ($data as $value){
            $temp = explode ("/", $value['Counter']['date_visit']);

  line 186  ====>  if ( $this->Time['year'] == $temp[2] ){
                if ( $prev_date == $temp[0] )
                    ++$this->Total_Yesterday;
                if ( $prev_mon == $temp['1'] )
                    ++$this->Total_Mon_Prev;
            }
        }

Thank you in advance for your answer.

ps: the lines concerned are: line 157 and line 186

我通过在指示的行之前添加以下代码解决了该问题

if (is_array($temp))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM