本文整理汇总了PHP中CHtml::activeDropDownList方法的典型用法代码示例。如果您正苦于以下问题:PHP CHtml::activeDropDownList方法的具体用法?PHP CHtml::activeDropDownList怎么用?PHP CHtml::activeDropDownList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CHtml
的用法示例。
在下文中一共展示了CHtml::activeDropDownList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* @inheritdoc
*/
public function run()
{
list($name, $id) = $this->resolveNameID();
if (isset($this->htmlOptions['id'])) {
$id = $this->htmlOptions['id'];
} else {
$this->htmlOptions['id'] = $id;
}
if (isset($this->htmlOptions['name'])) {
$name = $this->htmlOptions['name'];
}
if ($this->type == static::TYPE_TEXT) {
if ($this->hasModel()) {
echo \CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
} else {
echo \CHtml::textField($name, $this->value, $this->htmlOptions);
}
} elseif ($this->type == static::TYPE_SELECT) {
if ($this->hasModel()) {
echo \CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions);
} else {
echo \CHtml::dropDownList($name, $this->value, $this->data, $this->htmlOptions);
}
} else {
throw new \CException("Invalid field type '{$this->type}'");
}
$options = !empty($this->options) ? \CJavaScript::encode($this->options) : '';
$script = "jQuery('#{$id}').select2({$options})";
foreach ($this->events as $event => $handler) {
$script .= ".on('{$event}'," . \CJavaScript::encode($handler) . ")";
}
$script .= ';';
\Yii::app()->clientScript->registerScript(__CLASS__ . '#' . $this->getId(), $script);
$this->registerAssets();
}
示例2: run
public function run()
{
list($this->name, $this->id) = $this->resolveNameId();
if (isset($this->htmlOptions['placeholder'])) {
$this->options['placeholder'] = $this->htmlOptions['placeholder'];
}
$data = array();
if (isset($this->options['placeholder'])) {
$data[''] = '';
}
$this->data = $data + $this->data;
if ($this->hasModel()) {
echo CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions);
} else {
$this->htmlOptions['id'] = $this->id;
echo CHtml::dropDownList($this->name, $this->value, $this->data, $this->htmlOptions);
}
$bu = Yii::app()->assetManager->publish(dirname(__FILE__) . '/assets/');
$cs = Yii::app()->clientScript;
$cs->registerCssFile($bu . '/select2.css');
if ($this->scriptPosition === null) {
$this->scriptPosition = $cs->coreScriptPosition;
}
$cs->registerScriptFile($bu . '/select2.js', $this->scriptPosition);
$options = $this->options ? CJavaScript::encode($this->options) : '';
$cs->registerScript(__CLASS__ . '#' . $this->id, "\$('#{$this->id}').select2({$options});");
}
示例3: run
public function run()
{
list($name, $id) = $this->resolveNameID();
if (isset($this->htmlOptions['id'])) {
$id = $this->htmlOptions['id'];
} else {
$this->htmlOptions['id'] = $id;
}
if (isset($this->htmlOptions['name'])) {
$name = $this->htmlOptions['name'];
} else {
$this->htmlOptions['name'] = $name;
}
$l = Language::loadConfig();
$data = array();
foreach ($l['languages'] as $k => $v) {
$data[$k] = Yii::t('languages', $v);
}
if ($this->empty) {
$data = array_merge(array('' => Yii::t('cms', $this->empty)), $data);
}
if ($this->hasModel()) {
echo CHtml::activeDropDownList($this->model, $this->attribute, $data, $this->htmlOptions);
} else {
echo CHtml::dropDownList($name, $this->value, $data, $this->htmlOptions);
}
}
示例4: renderFilterCellContent
/**
* Renders the filter cell content. Here we can provide HTML options for actual filter input
*/
protected function renderFilterCellContent()
{
if (is_string($this->filter)) {
echo $this->filter;
} else {
if ($this->filter !== false && $this->grid->filter !== null && $this->name !== null && strpos($this->name, '.') === false) {
if ($this->filterInputOptions) {
$filterInputOptions = $this->filterInputOptions;
if (empty($filterInputOptions['id'])) {
$filterInputOptions['id'] = false;
}
} else {
$filterInputOptions = array();
}
if (is_array($this->filter)) {
$filterInputOptions['prompt'] = '';
echo CHtml::activeDropDownList($this->grid->filter, $this->name, $this->filter, $filterInputOptions);
} else {
if ($this->filter === null) {
echo CHtml::activeTextField($this->grid->filter, $this->name, $filterInputOptions);
}
}
} else {
parent::renderFilterCellContent();
}
}
}
示例5: run
/**
* Run this widget.
* This method registers necessary javascript and renders the needed HTML code.
*/
public function run()
{
list($name, $id) = $this->resolveDropDownNameID();
// Render drop-down element and hide it with javascript
if ($this->hasModel()) {
echo CHtml::activeDropDownList($this->model, $this->dropDownAttribute, $this->data, $this->dropDownHtmlOptions);
} else {
echo CHtml::dropDownList($name, $this->value, $this->data, $this->dropDownHtmlOptions);
}
// Put the script to hide the select-element directly after the element itself, so it is hidden directly after it is rendered
// Resource: http://www.electrictoolbox.com/jquery-hide-text-page-load-show-later/
// Note: You can also hide the select-element by adding the css-style 'display:none' to the dropDownHtmlOptions.
// We prefer the following JS-Code because of backward compatibility: if the user has JS disabled,
// multiselect will not work, but the original select-element will stay visible.
echo '<script type="text/javascript"> $("#' . $id . '").hide(); </script>';
$joptions = CJavaScript::encode($this->options);
$jfilterOptions = CJavaScript::encode($this->filterOptions);
if ($this->options['filter'] === true) {
$jscode = "jQuery('#{$id}').multiselect({$joptions}).multiselectfilter({$jfilterOptions});";
unset($this->options['filter']);
} else {
$jscode = "jQuery('#{$id}').multiselect({$joptions});";
}
// start - by jeremy@Yii
if ($this->options['ajaxRefresh'] == true) {
$jscode .= "jQuery('body').ajaxComplete(function() {jQuery('#" . $id . "').multiselect(" . $joptions . "); });";
}
// end - by jeremy@Yii
Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $id, $jscode);
}
示例6: renderField
/**
* Renders the select2 field
*/
public function renderField()
{
if ($this->hasModel()) {
echo $this->asDropDownList ? \CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->options) : \CHtml::activeHiddenField($this->model, $this->attribute);
} else {
echo $this->asDropDownList ? \CHtml::dropDownList($this->options['name'], $this->value, $this->data, $this->options) : \CHtml::hiddenField($this->options['name'], $this->value);
}
}
示例7: renderField
/**
* Renders the multiselect field
*/
public function renderField()
{
if ($this->hasModel()) {
echo \CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->options);
} else {
echo \CHtml::dropDownList($this->name, $this->value, $this->data, $this->options);
}
}
示例8: run
public function run()
{
echo CHtml::activeDropDownList($this->model, $this->attribute, $this->input_element->items, array(
'multiple' => 'multiple',
'key' => isset($this->key) ? $this->key : 'id',
'class' => 'multiselect'
));
}
示例9: editAttribute
/**
* @param $model - profile model
* @param $field - profile fields model item
* @param $params - htmlOptions
* @return string
*/
public function editAttribute($model,$field,$htmlOptions=array()) {
$list = array();
if ($this->params['emptyField']) $list[0] = $this->params['emptyField'];
$models = CActiveRecord::model($this->params['modelName'])->findAll();
foreach ($models as $m)
$list[$m->id] = (($this->params['optionName'])?$m->getAttribute($this->params['optionName']):$m->id);
return CHtml::activeDropDownList($model,$field->varname,$list,$htmlOptions=array());
}
示例10: renderField
public function renderField()
{
list($name, $id) = $this->resolveNameID();
if ($this->hasModel()) {
echo CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions);
} else {
echo CHtml::dropDownList($name, $this->value, $this->data, $this->htmlOptions);
}
}
示例11: run
public function run()
{
if ($this->selector == null) {
list($this->name, $this->id) = $this->resolveNameId();
$this->selector = '#' . $this->id;
if (isset($this->htmlOptions['placeholder'])) {
$this->options['placeholder'] = $this->htmlOptions['placeholder'];
}
if (!isset($this->htmlOptions['multiple'])) {
$data = array();
if (isset($this->options['placeholder'])) {
$data[''] = '';
}
$this->data = $data + $this->data;
}
if ($this->hasModel()) {
if (isset($this->options['ajax'])) {
echo CHtml::activeHiddenField($this->model, $this->attribute, $this->htmlOptions);
} else {
echo CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions);
}
} elseif (!isset($this->options['ajax'])) {
$this->htmlOptions['id'] = $this->id;
echo CHtml::dropDownList($this->name, $this->value, $this->data, $this->htmlOptions);
} else {
echo CHtml::hiddenField($this->name, $this->value, $this->htmlOptions);
}
}
$bu = Yii::app()->assetManager->publish(dirname(__FILE__) . '/assets/');
$cs = Yii::app()->clientScript;
//$cs->registerCssFile($bu . '/select2.css');
if (YII_DEBUG) {
$cs->registerScriptFile($bu . '/select2.js');
} else {
$cs->registerScriptFile($bu . '/select2.min.js');
}
if ($this->sortable) {
$cs->registerCoreScript('jquery.ui');
}
$options = CJavaScript::encode(CMap::mergeArray($this->defaultOptions, $this->options));
ob_start();
echo "jQuery('{$this->selector}').select2({$options})";
foreach ($this->events as $event => $handler) {
echo ".on('{$event}', " . CJavaScript::encode($handler) . ")";
}
echo ';';
if ($this->sortable) {
echo <<<JavaScript
jQuery('{$this->selector}').select2("container").find("ul.select2-choices").sortable({
\tcontainment: 'parent',
\tstart: function() { jQuery('{$this->selector}').select2("onSortStart"); },
\tupdate: function() { jQuery('{$this->selector}').select2("onSortEnd"); }
});
JavaScript;
}
$cs->registerScript(__CLASS__ . '#' . $this->id, ob_get_clean());
}
示例12: renderField
public function renderField()
{
$this->htmlOptions['multiple'] = 'multiple';
if ($this->hasModel()) {
echo CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions);
} else {
echo CHtml::dropDownList($this->name, $this->value, $this->data, $this->htmlOptions);
}
}
示例13: enumDropDownList
public static function enumDropDownList($model, $attribute, $htmlOptions = array(), $default = NULL)
{
$enumValues = self::enumItem($model, $attribute);
if (!empty($default)) {
// This will return a <option value="defaul"></option>
$enumValues = array($default['value'] => (string) $default['label']) + $enumValues;
}
// echo var_export($enumValues, TRUE);
return CHtml::activeDropDownList($model, $attribute, $enumValues, $htmlOptions);
}
示例14: run
public function run()
{
$type = DataType::getInputType($this->column->dbType);
$this->htmlOptions += $this->fixedHtmlOptions[$type];
$column = $this->column->name;
$name = isset($this->htmlOptions['name']) ? $this->htmlOptions['name'] : 'Row[' . $column . ']';
switch ($type) {
case 'number':
echo CHtml::activeTextField($this->row, $column, $this->htmlOptions);
break;
case 'select':
echo CHtml::activeDropDownList($this->row, $column, $this->getEnumValues(), $this->htmlOptions);
break;
case 'select-multiple':
#echo CHtml::activeListBox($this->row, $column, $this->getSetValues(), $this->htmlOptions);
echo CHtml::listBox($name, $this->row->getAttributeAsArray($column), $this->getSetValues(), $this->htmlOptions);
break;
case 'text':
echo CHtml::activeTextArea($this->row, $column, $this->htmlOptions);
break;
case 'file':
echo '<script type="text/javascript">
$(document).ready(function() {
$("# echo CHtml::$idPrefix; ?>").submit(function() {
alert("ok1");
});
});
</script>';
echo CHtml::activeFileField($this->row, $column, $this->htmlOptions);
break;
case 'date':
$this->SetDateTimeHtmlOptions($column);
echo CHtml::activeTextField($this->row, $column, $this->htmlOptions);
echo '<script type="text/javascript">
$(document).ready(function() {
$("#' . $this->htmlOptions['id'] . '").datepicker({showOn: "button", dateFormat: "yy-mm-dd", buttonImage: "' . ICONPATH . '/16/calendar.png' . '", buttonImageOnly: true, buttonText: "' . Yii::t('core', 'showCalendar') . '"});
});
</script>';
break;
case 'datetime':
$this->SetDateTimeHtmlOptions($column);
echo CHtml::activeTextField($this->row, $column, $this->htmlOptions);
echo '<script type="text/javascript">
$(document).ready(function() {
now = new Date();
$("#' . $this->htmlOptions['id'] . '").datepicker({showOn: "button", dateFormat: "yy-mm-dd " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds(), buttonImage: "' . ICONPATH . '/16/calendar.png' . '", buttonImageOnly: true, buttonText: "' . Yii::t('core', 'showCalendar') . '"});
});
</script>';
break;
default:
echo CHtml::activeTextField($this->row, $column, $this->htmlOptions);
break;
}
}
示例15: renderField
/**
* Renders the select2 field
*/
public function renderField()
{
list($name, $id) = $this->resolveNameID();
TbArray::defaultValue('id', $id, $this->htmlOptions);
TbArray::defaultValue('name', $name, $this->htmlOptions);
if ($this->hasModel()) {
echo $this->asDropDownList ? CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions) : CHtml::activeHiddenField($this->model, $this->attribute);
} else {
echo $this->asDropDownList ? CHtml::dropDownList($this->name, $this->value, $this->data, $this->htmlOptions) : CHtml::hiddenField($this->name, $this->value);
}
}