Nima
Nima

Reputation: 15

Yii get cached object auto load CTimestampBehavior

How cache an model instance or array of models including 'CTimestampBehavior' behavior and retrieve it correctly in Yii? I need to set cache array of models in console command and get them in web-app. It being retrieved fine in console but I'm getting this warning in web-app :

include(CTimestampBehavior.php): failed to open stream: No such file or directory

It happens only for models which have 'CTimestampBehavior' behavior.

it's trace;

2013/12/21 12:56:59 [error] [php] include(CTimestampBehavior.php): failed to open stream: No such file or directory (C:\xampp\htdocs\yii\framework\YiiBase.php:427)
Stack trace:
#0 unknown(0): spl_autoload_call()
#1 C:\xampp\htdocs\yii\framework\caching\CCache.php(108): unserialize()
#2 C:\xampp\htdocs\inews\themes\news\views\site\index.php(3): CFileCache->get()
#3 C:\xampp\htdocs\yii\framework\web\CBaseController.php(126): require()
#4 C:\xampp\htdocs\yii\framework\web\CBaseController.php(95): SiteController->renderInternal()
#5 C:\xampp\htdocs\yii\framework\web\CController.php(869): SiteController->renderFile()
#6 C:\xampp\htdocs\yii\framework\web\CController.php(782): SiteController->renderPartial()
#7 C:\xampp\htdocs\inews\protected\controllers\SiteController.php(40): SiteController->render()
#8 C:\xampp\htdocs\yii\framework\web\actions\CInlineAction.php(49): SiteController->actionIndex()
#9 C:\xampp\htdocs\yii\framework\web\CController.php(308): CInlineAction->runWithParams()
#10 C:\xampp\htdocs\yii\framework\web\CController.php(286): SiteController->runAction()
#11 C:\xampp\htdocs\yii\framework\web\CController.php(265): SiteController->runActionWithFilters()
#12 C:\xampp\htdocs\yii\framework\web\CWebApplication.php(282): SiteController->run()
#13 C:\xampp\htdocs\yii\framework\web\CWebApplication.php(141): CWebApplication->runController()
#14 C:\xampp\htdocs\yii\framework\base\CApplication.php(180): CWebApplication->processRequest()
#15 C:\xampp\htdocs\inews\index.php(13): CWebApplication->run()
REQUEST_URI=/inews/site/index
in C:\xampp\htdocs\inews\themes\news\views\site\index.php (3)
in C:\xampp\htdocs\inews\protected\controllers\SiteController.php (40)
in C:\xampp\htdocs\inews\index.php (13)

Console function:

public function actionZe() {
        $timeLimit = date('Y-m-d H-i-s', strtotime('-1 month'));
        $articles = Article::model()->limit(6)->order('view_counter DESC')->findAll('Status="OK" AND CreationDate >  "'.$timeLimit.'"');

        Yii::app()->cache->set('Hot_Articles', $articles, 120);
        $value = Yii::app()->cache->get('Hot_Articles');//WORKS
        print_r($value);
    }

WebApp :

    $value = Yii::app()->cache->get('Hot_Articles');//Doesn't Work
    print_r($value );
    die();

Upvotes: 1

Views: 708

Answers (1)

JPR
JPR

Reputation: 869

You need to import the file.

Yii::import('zii.behaviors.CTimestampBehavior');

or in your config file

'import' => array(
    ....
    'zii.behaviors.CTimestampBehavior' // or 'zii.behaviors.*'
    ....
)

Upvotes: 2

Related Questions