Datetime Widget И Формат Даты

Приветствую.

Тут такое дело. Я написал виджет DatePicker и использую его в фильтрах CGridWiew.




		array(

			'name' => 'created',

			'value' => 'Yii::app()->format->formatDate($data->created)',

			'type' => 'raw',

			'htmlOptions' => array('class' => 'span1'),

			'filter' => $this->widget('application.widgets.TDatePicker.TDatePicker', array(

				'model' => $model,

				'attribute' => 'created',

				'htmlOptions' => array('id' => 'created'),

			), true)

		),



Виджет работает, с ним проблем нет. Проблема в том, что я хочу чтобы дата в фильтре была в формате d.m.Y. В клиентских скриптах я устанавливаю формат через options виджета.

Но после перезагрузки грида, дата в поле фильтра выводится в формате mysql (Y-m-d).

Перепробовал уже кучу вариантов, пробовал даже в value фильтра указывать


'value' => 'Yii::app()->format->formatDate($model->created)',

ни в какую.

Сейчас сделал формат даты в методе run виджета




	public function run() {

		parent::run();

		list($name, $id) = $this->resolveNameID();


		if ($this->hasModel()) {

			$attribute = $this->attribute;

			if (!empty($this->model->$attribute)) {

				$this->model->$attribute = Yii::app()->format->formatDate($this->model->$attribute);

			}

			echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);

		} else {

			echo CHtml::textField($name, $this->value, $this->htmlOptions);

		}


		$this->registerClientScript($id);

	}



Но это костыль. Т.к. виджет может использоваться не только в фильтрах грида, но и формах. И если в фильтрах нужна только дата, то в формах нужно будет и время.

Поэтому как-то хотелось бы указывать виджету именно формат даты или метод, которым дату форматировать.

Подскажите, как бы вы сделали это по правильному?

Вот весь код виджета




class TDatePicker extends CInputWidget {

	/**

	 * @var array the options for the Datetimepicker JavaScript plugin.

	 */

	public $options = array();


	private $__cssFile = null;

	private $__jsFile = null;

	private $__localeFile = null;


	/**

	 * Initializes the widget.

	 */

	public function init() {

		parent::init();

		$this->htmlOptions['type'] = 'text';

		$this->htmlOptions['autocomplete'] = 'off';


		if (!isset($this->options['language'])) {

			$this->options['language'] = Yii::app()->language;

		}


		if (!isset($this->options['format'])) {

			$this->options['format'] = Yii::app()->format->clientDateFormat;

		}


		if (!isset($this->options['autoclose'])) {

			$this->options['autoclose'] = true;

		}


		if (!isset($this->options['minView'])) {

			$this->options['minView'] = 2;

		}


		$this->__registerAsset();

	}


	/**

	 * Runs the widget.

	 */

	public function run() {

		parent::run();

		list($name, $id) = $this->resolveNameID();


		if ($this->hasModel()) {

			$attribute = $this->attribute;

			if (!empty($this->model->$attribute)) {

				$this->model->$attribute = Yii::app()->format->formatDate($this->model->$attribute);

			}

			echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);

		} else {

			echo CHtml::textField($name, $this->value, $this->htmlOptions);

		}


		$this->registerClientScript($id);

	}


	private function __registerAsset() {

		$this->__cssFile = Yii::app()->getAssetManager()->publish(

			dirname(__FILE__) . '/assets/css/datetimepicker.css'

		);

		$this->__jsFile = Yii::app()->getAssetManager()->publish(

			dirname(__FILE__) . '/assets/js/bootstrap-datetimepicker.js'

		);

		$this->__localeFile = Yii::app()->getAssetManager()->publish(

			dirname(__FILE__) . '/assets/js/locales/bootstrap-datetimepicker.' . Yii::app()->language . '.js'

		);

	}


	/**

	 * Registers required client script for bootstrap datepicker. It is not used through bootstrap->registerPlugin

	 * in order to attach events if any

	 */

	public function registerClientScript($id) {

		Yii::app()->clientScript->registerCssFile($this->__cssFile);

		Yii::app()->clientScript->registerScriptFile($this->__jsFile, CClientScript::POS_END);

		Yii::app()->clientScript->registerScriptFile($this->__localeFile, CClientScript::POS_END);

		$options = !empty($this->options) ? CJavaScript::encode($this->options) : '';


		ob_start();

		echo "jQuery('#{$id}').datetimepicker({$options})";

//		foreach ($this->events as $event => $handler)

//			echo ".on('{$event}', " . CJavaScript::encode($handler) . ")";


		Yii::app()->clientScript->registerScript(__CLASS__ . '#' . $this->getId(), ob_get_clean() . ';');

	}


	public static function gridAfterAjax($ids, $options = null) {

		if (!is_array($ids)) {

			$ids = array($ids);

		}


		if (!isset($options['format'])) {

			$options['format'] = Yii::app()->format->clientDateFormat;

		}

		if (!isset($options['autoclose'])) {

				$options['autoclose'] = true;

		}

		if (!isset($options['minView'])) {

			$options['minView'] = 2;

		}

		$options = CJavaScript::encode($options);

		foreach ($ids as &$id) {

			$id = '#' . $id;

		}


		return "function() { jQuery('" . implode(',', $ids) . "').datetimepicker({$options}); }";

	}

}