Skip to content

Instantly share code, notes, and snippets.

@jamband
Last active September 30, 2015 08:38
Show Gist options
  • Save jamband/1753872 to your computer and use it in GitHub Desktop.
Save jamband/1753872 to your computer and use it in GitHub Desktop.
Yii Framework: How to reduce the amount of the widget code.
<?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model' => $model,
'attribute' => $attribute,
'language' => 'ja',
'options' => array(
'dateFormat' => 'yy-mm-dd',
'yearRange' => '-70:+0',
'changeYear' => 'true',
'changeMonth' => 'true',
'showButtonPanel' => 'true',
'showOn' => 'both',
'buttonImage' => '/images/calendar.png',
'buttonImageOnly' => 'true',
),
)); ?>
<?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model' => $model,
'attribute' => 'birth',
'language' => 'ja',
'options' => array(
'dateFormat' => 'yy-mm-dd',
'yearRange' => '-70:+0',
'changeYear' => 'true',
'changeMonth' => 'true',
'showButtonPanel' => 'true',
'showOn' => 'both',
'buttonImage' => '/images/calendar.png',
'buttonImageOnly' => 'true',
),
)); ?>
<?php
return array(
...
'components' => array(
...
'widgetFactory' => array(
'widgets' => array(
'CJuiDatePicker' => array(
'language' => 'ja',
'options' => array(
'dateFormat' => 'yy-mm-dd',
'yearRange' => '-70:+0',
'changeYear' => 'true',
'changeMonth' => 'true',
'showButtonPanel' => 'true',
'showOn' => 'both',
'buttonImage' => '/images/calendar.png',
'buttonImageOnly' => 'true',
),
),
),
),
...
<?php
Yii::import('zii.widgets.jui.CJuiDatePicker');
/**
* MyDatePicker class file.
*/
class MyDatePicker extends CJuiDatePicker
{
/**
* @see CJuiDatePicker::language
*/
public $language = 'ja';
/**
* @see CJuiWidget::options
*/
public $options = array(
'dateFormat' => 'yy-mm-dd',
'yearRange' => '-70:+0',
'changeYear' => 'true',
'changeMonth' => 'true',
'showButtonPanel' => 'true',
'showOn' => 'both',
'buttonImage' => '/images/calendar.png',
'buttonImageOnly' => 'true',
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment