Cfilevalidator Works Locally, Not In Production

Wondering if anyone has run into this before, or knows a possible fix…

Basically I have a form, one of the fields is a file upload field. On this field, I have a file validation rule. When I have this rule on that field, CForm will not render it. If I change it to ‘safe’ or some other validation rule, it is rendered. The strange thing is that when working locally, if I have the file validation rule on it, the field renders fine; it’s only on my production box that it doesn’t. My first thought is maybe case-sensitivity issues (i.e. using Yii::import(‘CJavascript’) works on my Mac, but not in production, it needs to be CJavaScript), but I’ve found that CFileValidation is being instantiated fine. I’ve been playing with it more, and I’ve narrowed the problem down to a property on CFileValidation: public $safe=false; When I comment it out, the field renders on production, but when it’s uncommented, it doesn’t. Does anyone have any ideas? Sample code below.




class SiteController extends CController

{

	public function actionTest(){

		$config=array(

			'elements'=>array(

				'test'=>array(

					'type'=>'file',

					'label'=>'Test',

				),

			),

			'buttons'=>array(

				'submit'=>array(

					'type'=>'submit',

					'label'=>'asf',

				),

			),

		);

		

		$a=new TestFormModel;

		$b=new CForm($config,$a);

		

		echo $b;

	}

}


class TestFormModel extends CFormModel {

	public $test;

	

	public function rules()

	{

		return array(

			array('test','ext.validators.TestValidator'),

		);

	}

}


class TestValidator extends CValidator

{

	//public $safe=false;


	// .... same exact code as CFileValidator except class name is changed

}



To anyone interested:

Turns out the problem was we were using an older version of Yii locally, and our production boxes has an updated version of it. CForm won’t render a field with a file validation rule on it if it doesn’t have the safe property set to true. This safe property wasn’t in the older version of Yii, so it worked locally. Here is the correct code:




class TestFormModel extends CFormModel {

        public $test;

        

        public function rules()

        {

                return array(

                        array('test','file','safe'=>true),

                );

        }

}