CTimestampBehavior from zii

When using CTimestampBehavior in the zii extension dir, do i need to copy it to the extension or components dir under protected?

i added this to my active record model




	public function behaviors()

	{

		return array(

			'CTimestampBehavior' => array(

				'class' => 'CTimestampBehavior',

				/*

				'createAttribute' => 'create_time',

				'updateAttribute' => 'update_time',

				*/

			)

		);

	}



but got the following error




PHP Error

Description


require(CTimestampBehavior.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory

Source File


C:\wamp\www\yii\framework\YiiBase.php(236)

00224: 

00225:         if(class_exists($alias,false) || interface_exists($alias,false))

00226:             return self::$_imports[$alias]=$alias;

00227: 

00228:         if(isset(self::$_coreClasses[$alias]) || ($pos=strrpos($alias,'.'))===false)  // a simple class name

00229:         {

00230:             self::$_imports[$alias]=$alias;

00231:             if($forceInclude)

00232:             {

00233:                 if(isset(self::$_coreClasses[$alias])) // a core class

00234:                     require(YII_PATH.self::$_coreClasses[$alias]);

00235:                 else

00236:                     require($alias.'.php');// error line

00237:             }

00238:             return $alias;

00239:         }

00240: 

00241:         if(($className=(string)substr($alias,$pos+1))!=='*' && (class_exists($className,false) || interface_exists($className,false)))

00242:             return self::$_imports[$alias]=$className;

00243: 

00244:         if(($path=self::getPathOfAlias($alias))!==false)

00245:         {

00246:             if($className!=='*')

00247:             {

00248:                 self::$_imports[$alias]=$className;

Stack Trace



I know how to include files or whatever but is this suppose to happen if i simply add that method to my model?

this is in yii 1.1 alpha from the trunk

To use classes in zii, you need to reference them with complete path: zii.behaviors.CTimestampBehavior

Thank you Qiang. For anyone who might have had the same question, what he meant is that i need to change


		return array(

			'CTimestampBehavior' => array(

				'class' => 'CTimestampBehavior',...

to


		return array(

			'CTimestampBehavior' => array(

				'class' => 'zii.behaviors.CTimestampBehavior',...

You sir, are where it’s at.

Hello,

I am using this behavior, but sometimes, I received this message:


Fatal error: method_exists() [function.method-exists]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "CTimestampBehavior" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in D:\Development\YII\yii\framework\base\CComponent.php on line 538

Does anyone know how to solve the problem?

I got this problem too. I added this class to the autoload imports list in config/main.php:




'import' => array(

	(...)

	'zii.behaviors.CTimestampBehavior',		

),



I think I shouldn’t have to do this. If anyone has a better idea, please say so.

For the info I had the exact same problem, for only one particular model and I also fixed it with the import in the config file.