0

我正在使用文件缓存 (CFileCache) 来显示来自数据库表的简单消息。第一次加载页面时它可以正常工作,但是当我重新加载页面时它会出错:include(CTimestampBehavior.php)[function.include]:无法打开流:没有这样的文件或目录

并且此错误一直存在,直到我在 cache->set() 中设置的 TIME EXPIRATION 并且下一页仅加载一次,然后再次出错,依此类推。

这是我处理缓存的方法:

public static function getLatest()
    {

        //see if it is in the cache, if so, just return it
        if( ($cache=Yii::app()->cache)!==null)
        {

            $key='TrackStar.ProjectListing.SystemMessage';
            if(($sysMessage=$cache->get($key))!==false)
            return $sysMessage;
        }
        //The system message was either not found in the cache, or
        //there is no cache component defined for the application
        //retrieve the system message from the database

        $sysMessage = SysMessage::model()->find(array(
        'order'=>'t.update_time DESC',
        ));
        if($sysMessage != null)
        {
            //a valid message was found. Store it in cache for future retrievals
            if(isset($key))
                //$cache->set($key,$sysMessage,300);
                $cache->set($key, $sysMessage, 300, new CDbCacheDependency('SELECT MAX(update_time) FROM tbl_sys_message'));
            return $sysMessage;
        }
        else
        return null;
    }

此行出现错误:

if(($sysMessage=$cache->get($key))!==false)

我是 Yii 和缓存的新手,对此一无所知。

更新:AR模型的行为方法:

public function behaviors()
        {
            return array(
                'CTimestampBehavior' => array(
                'class' => 'zii.behaviors.CTimestampBehavior',
                'createAttribute' => 'create_time',
                'updateAttribute' => 'update_time',
                'setUpdateOnCreate' => true,
                ),
            );
        }
4

1 回答 1

1

这看起来像您的问题是:

  • 缺少框架/zii/behaviors/CTimestampBehavior.php
  • framework/zii/behaviors/CTimestampBehavior.php 没有正确的权限被您的服务器用户读取
  • 您正在使用操作码缓存(APC?),并且在这方面存在一些问题(尽管对此的报告似乎是随机发生的)。尝试禁用它。
  • 由于某些未知原因,Yii 不导入您的 zii 路线

无论如何,我建议尝试将“zii.behaviors.CTimestampBehavior”添加到您的 main.php 配置文件“导入”部分的解决方法。或者简单地调用 Yii::import('zii.behaviors.CTimestampBehavior'); 在你的功能中。希望这行得通,您可以在有时间的时候继续您的工作,同时深入研究这个问题。

如果不是,您可以调查上述内容(至少来这里的人会有更多信息可以使用)

于 2013-03-07T00:56:43.637 回答