本文整理汇总了PHP中CHtml::resolveNameID方法的典型用法代码示例。如果您正苦于以下问题:PHP CHtml::resolveNameID方法的具体用法?PHP CHtml::resolveNameID怎么用?PHP CHtml::resolveNameID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CHtml
的用法示例。
在下文中一共展示了CHtml::resolveNameID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: movieNameFieldControlGroup
/**
* Renders a text field with typeahead functionality based on the specified
* data.
* @param CModel $model the model
* @param string $attribute the attribute name
* @param array $htmlOptions options to pass to the control group
* @return string the HTML for the input
*/
public function movieNameFieldControlGroup($model, $attribute, $htmlOptions = array())
{
// Generate a unique ID for this element
CHtml::resolveNameID($model, $attribute, $htmlOptions);
$id = $htmlOptions['id'];
Yii::app()->clientScript->registerScript($id, $this->getMovieNameTypeaheadScript($id, $htmlOptions), CClientScript::POS_READY);
return $this->textFieldControlGroup($model, $attribute, $htmlOptions);
}
示例2: registerScript
function registerScript()
{
CHtml::resolveNameID($this->model, $this->attribute, $this->htmlOptions);
$nameId = $this->htmlOptions['id'];
$js = "\$('#{$this->attribute}').typeahead({\n source: function(query, process) {\n objects = [];\n map = {};\n \$.get('{$this->url}', {query: query}, function(data){\n for(var i=0; i<data.length; i++){\n map[data[i].value] = data[i].id;\n objects.push(data[i].value);\n }\n process(objects);\n }, 'json'); \n },\n updater: function(item) {\n \$('#{$nameId}').val(map[item]);\n return item;\n }\n });";
list(, $id) = $this->resolveNameID();
Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $id, $js);
}
示例3: init
public function init()
{
parent::init();
$attrs = array();
CHtml::resolveNameID($this->model, $this->source, $attrs);
$options = CJavaScript::encode(array('source' => $attrs['id'], 'destination' => $this->id, 'urlSeparator' => $this->divider));
Yii::app()->clientScript->registerScriptFile($this->assets . '/jquery.synctranslit.js')->registerScriptFile($this->assets . '/alias.js')->registerScript($this->id . '_alias', "\$('#{$this->id}').alias({$options});");
}
示例4: typeaheadFieldControlGroup
/**
* Renders a text field with typeahead functionality based on the specified
* data.
* @param CModel $model the model
* @param string $attribute the attribute name
* @param string $data JavaScript-encoded array containing the data for the
* typeahead
* @param array $htmlOptions options to pass to the control group
* @return string the HTML for the input
*/
public function typeaheadFieldControlGroup($model, $attribute, $data, $htmlOptions = array())
{
// Generate a unique ID for this element
CHtml::resolveNameID($model, $attribute, $htmlOptions);
TbHtml::addCssClass('twitter-typeahead-input', $htmlOptions);
$id = $htmlOptions['id'];
Yii::app()->clientScript->registerScript($id, "\n\t\t\t\$('#{$id}').typeahead({name: '{$id}',local: {$data},limit: 10});\n\t\t", CClientScript::POS_READY);
return $this->textFieldControlGroup($model, $attribute, $htmlOptions);
}
示例5: ueditor
public function ueditor($model, $attribute, $htmlOptions = array())
{
//得到这个插件的name
CHtml::resolveNameID($model, $attribute, $htmlOptions);
$attr = 'name="' . $htmlOptions['name'] . '" style="' . $htmlOptions['style'] . '"';
$content = $model->content ? $model->content : '';
$str = '<script type="text/javascript" src="/themes/abound/js/ueditor/ueditor.config.js"></script>';
$str .= '<script type="text/javascript" src="/themes/abound/js/ueditor/ueditor.all.min.js"></script>';
$str .= '<script type="text/javascript" src="/themes/abound/js/ueditor/lang/zh-cn/zh-cn.js"></script>';
$str .= '<script id="editor" type="text/plain" ' . $attr . '>' . html_entity_decode($content) . '</script>';
$str .= '<script type="text/javascript">var ue = UE.getEditor(\'editor\');</script>';
return $str;
}
示例6: getModelAttributes
public static function getModelAttributes($modelClass, array $attributes = array())
{
/** @var CModel $model */
$model = new $modelClass();
$labels = $model->attributeLabels();
$adapterAttributes = array();
foreach ($labels as $name => $label) {
if (!empty($attributes) && !in_array($name, $attributes)) {
continue;
}
$tmp = array();
CHtml::resolveNameID($model, $name, $tmp);
$adapterAttributes[] = array('name' => $tmp['id'], 'map' => $name, 'label' => $label);
}
return $adapterAttributes;
}
示例7: activeRadioButtonList
public static function activeRadioButtonList($model, $attribute, $data, $htmlOptions = array())
{
CHtml::resolveNameID($model, $attribute, $htmlOptions);
$selection = CHtml::resolveValue($model, $attribute);
if ($model->hasErrors($attribute)) {
CHtml::addErrorCss($htmlOptions);
}
$name = $htmlOptions['name'];
unset($htmlOptions['name']);
if (array_key_exists('uncheckValue', $htmlOptions)) {
$uncheck = $htmlOptions['uncheckValue'];
unset($htmlOptions['uncheckValue']);
} else {
$uncheck = '';
}
$hiddenOptions = isset($htmlOptions['id']) ? array('id' => CHtml::ID_PREFIX . $htmlOptions['id']) : array('id' => false);
$hidden = $uncheck !== null ? CHtml::hiddenField($name, $uncheck, $hiddenOptions) : '';
return $hidden . self::radioButtonList($name, $selection, $data, $htmlOptions);
}
示例8: addActiveField
/**
* Add a field into form
*
* @param CModel $model
* @param string $attribute
* @param string $inputType
*/
public function addActiveField($model, $attribute, $inputType, $htmlOptions = array(), $scenario = null)
{
CHtml::resolveNameID($model, $attribute, $htmlOptions);
$label = $model->getAttributeLabel($attribute);
$value = $model->{$attribute};
if (!isset($htmlOptions['data-source'])) {
$htmlOptions['data-source'] = $attribute;
}
$this->fields[$htmlOptions['id']] = array('label' => $label, 'type' => $inputType, 'id' => $htmlOptions['id'], 'name' => $htmlOptions['name'], 'value' => $value, 'htmlOptions' => $htmlOptions);
/** validators */
$this->rules[$htmlOptions['id']] = array();
$validators = $model->getValidators($attribute);
foreach ($validators as $validator) {
$valType = get_class($validator);
$validator = get_class_vars($valType);
$valType = str_replace('Validator', '', substr($valType, 1));
$validator['type'] = $valType;
unset($validator['builtInValidators']);
$validator['message'] = $this->getErrorMessage($valType, $attribute, $label);
$this->rules[$htmlOptions['id']][] = $validator;
}
}
示例9: run
function run()
{
if ($this->hasModel()) {
// required!
$this->htmlOptions['autocomplete'] = 'off';
echo CHtml::textField($this->attribute, $this->value, $this->htmlOptions);
echo '<span class="help-block">' . Yii::t('common', '(Autocomplete)') . '</span>';
CHtml::resolveNameID($this->model, $this->attribute, $this->htmlOptions);
$this->_containerId = $this->htmlOptions['id'] . "_container";
$this->_nameId = $this->htmlOptions['name'];
echo "<div id='{$this->_containerId}' class='well scrollbox'>";
if (count($this->model->attributes[$this->attribute]) > 0) {
$elements = $this->model->attributes[$this->attribute];
foreach ($elements as $id => $name) {
echo "<div>{$name}<i class=\"icon-remove\"></i><input type=\"hidden\" value=\"{$id}\" name=\"{$this->_nameId}[]\"></div>";
}
}
echo "</div>";
$this->registerScript();
} else {
// TODO: extend widget to support non-active input
throw new CException(Yii::t('errors', 'TypeaheadMultiple doesn\'t support non-active records. Please add a model attribute to the widget to use.'));
}
}
示例10: inputsList
/**
* Renders an input list.
* @param boolean $checkbox flag that indicates if the list is a checkbox-list.
* @param CModel $model the data model
* @param string $attribute the attribute
* @param array $data value-label pairs used to generate the input list.
* @param array $htmlOptions additional HTML options.
* @return string the generated input list.
* @since 0.9.5
*/
protected function inputsList($checkbox, $model, $attribute, $data, $htmlOptions = array())
{
CHtml::resolveNameID($model, $attribute, $htmlOptions);
$select = CHtml::resolveValue($model, $attribute);
if ($model->hasErrors($attribute)) {
if (isset($htmlOptions['class'])) {
$htmlOptions['class'] .= ' ' . CHtml::$errorCss;
} else {
$htmlOptions['class'] = CHtml::$errorCss;
}
}
$name = $htmlOptions['name'];
unset($htmlOptions['name']);
if (array_key_exists('uncheckValue', $htmlOptions)) {
$uncheck = $htmlOptions['uncheckValue'];
unset($htmlOptions['uncheckValue']);
} else {
$uncheck = '';
}
$hiddenOptions = isset($htmlOptions['id']) ? array('id' => CHtml::ID_PREFIX . $htmlOptions['id']) : array('id' => false);
$hidden = $uncheck !== null ? CHtml::hiddenField($name, $uncheck, $hiddenOptions) : '';
if (isset($htmlOptions['template'])) {
$template = $htmlOptions['template'];
} else {
$template = '<label class="{labelCssClass}">{input}{label}</label>';
}
unset($htmlOptions['template'], $htmlOptions['separator'], $htmlOptions['hint']);
if ($checkbox && substr($name, -2) !== '[]') {
$name .= '[]';
}
unset($htmlOptions['checkAll'], $htmlOptions['checkAllLast']);
$labelOptions = isset($htmlOptions['labelOptions']) ? $htmlOptions['labelOptions'] : array();
unset($htmlOptions['labelOptions']);
$items = array();
$baseID = CHtml::getIdByName($name);
$id = 0;
$method = $checkbox ? 'checkBox' : 'radioButton';
$labelCssClass = $checkbox ? 'checkbox' : 'radio';
if (isset($htmlOptions['inline'])) {
$labelCssClass .= '-inline';
unset($htmlOptions['inline']);
}
foreach ($data as $value => $label) {
$checked = !is_array($select) && !strcmp($value, $select) || is_array($select) && in_array($value, $select);
$htmlOptions['value'] = $value;
$htmlOptions['id'] = $baseID . '_' . $id++;
$option = CHtml::$method($name, $checked, $htmlOptions);
$label = CHtml::label($label, $htmlOptions['id'], $labelOptions);
$items[] = strtr($template, array('{labelCssClass}' => $labelCssClass, '{input}' => $option, '{label}' => $label));
}
return $hidden . implode('', $items);
}
示例11: activeDateField
public static function activeDateField($model, $attribute, $htmlOptions = array())
{
// SET UP ARRAYS OF OPTIONS FOR DAY, MONTH, YEAR
$x = 1;
$dayOptions = array('00' => ' - ');
while ($x < 31) {
$dayOptions[($x < 10 ? '0' : '') . $x] = $x;
$x++;
}
$monthOptions = array('00' => ' - ', '01' => UserModule::t('January'), '02' => UserModule::t('February'), '03' => UserModule::t('March'), '04' => UserModule::t('April'), '05' => UserModule::t('May'), '06' => UserModule::t('June'), '07' => UserModule::t('July'), '08' => UserModule::t('August'), '09' => UserModule::t('September'), '10' => UserModule::t('October'), '11' => UserModule::t('November'), '12' => UserModule::t('December'));
$yearOptions = array('0000' => ' - ');
$x = 1901;
while ($x < 2030) {
$yearOptions[$x] = $x;
$x++;
}
parent::resolveNameID($model, $attribute, $htmlOptions);
if ($model->{$attribute} != '0000-00-00' && isset($model->{$attribute})) {
if (is_array($model->{$attribute})) {
$new = $model->{$attribute};
$day = $new['day'];
$month = $new['month'];
$year = $new['year'];
} else {
$new = explode('-', $model->{$attribute});
// intval removes leading zero
$day = $new[2];
$month = $new[1];
$year = $new[0];
}
} else {
// DEFAULT TO 0 IF THERE IS NO DATE SET
$day = '00';
$month = '00';
$year = '0000';
}
//echo "<pre>"; print_r(array($day,$month,$year)); die();
$return = parent::dropDownList($htmlOptions['name'] . '[day]', $day, $dayOptions);
$return .= parent::dropDownList($htmlOptions['name'] . '[month]', $month, $monthOptions);
$return .= parent::dropDownList($htmlOptions['name'] . '[year]', $year, $yearOptions);
return $return;
}
示例12: activeTextInputField
/**
* Generates an input HTML tag for a model attribute.
* This method generates an input HTML tag based on the given input name and value.
* @param string $type the input type.
* @param CModel $model the data model.
* @param string $attribute the attribute.
* @param array $htmlOptions additional HTML attributes.
* @return string the generated input tag.
*/
protected static function activeTextInputField($type, $model, $attribute, $htmlOptions)
{
parent::resolveNameID($model, $attribute, $htmlOptions);
parent::clientChange('change', $htmlOptions);
$htmlOptions = self::normalizeInputOptions($htmlOptions);
$addOnClasses = self::getAddOnClasses($htmlOptions);
$addOnOptions = TbArray::popValue('addOnOptions', $htmlOptions, array());
self::addCssClass($addOnClasses, $addOnOptions);
$prepend = TbArray::popValue('prepend', $htmlOptions, '');
$prependOptions = TbArray::popValue('prependOptions', $htmlOptions, array());
if (!empty($prepend)) {
$prepend = self::inputAddOn($prepend, $prependOptions);
}
$append = TbArray::popValue('append', $htmlOptions, '');
$appendOptions = TbArray::popValue('appendOptions', $htmlOptions, array());
if (!empty($append)) {
$append = self::inputAddOn($append, $appendOptions);
}
$output = '';
if (!empty($addOnClasses)) {
$output .= self::openTag('div', $addOnOptions);
}
$output .= $prepend . parent::activeInputField($type, $model, $attribute, $htmlOptions) . $append;
if (!empty($addOnClasses)) {
$output .= '</div>';
}
return $output;
}
示例13: activeUneditableField
/**
* Generates an uneditable input for a model attribute.
* @param CModel $model the data model.
* @param string $attribute the attribute.
* @param array $htmlOptions additional HTML attributes.
* @return string the generated input.
*/
public static function activeUneditableField($model, $attribute, $htmlOptions = array())
{
parent::resolveNameID($model, $attribute, $htmlOptions);
$value = parent::resolveValue($model, $attribute);
BsArray::removeValues(array('name', 'id'), $htmlOptions);
return self::uneditableField($value, $htmlOptions);
}
示例14: init
public function init()
{
parent::init();
// ensure necessary assets are loaded
// JJD 8/3/11 make EJuiAutoCompleteFkField work for child rows where attribute like [$i]FieldName
// get the ID which will be created for the actual field when it is rendered.
// don't let resolveNameID() change $this->attribute which is needed to generate the actual field
$attr = $this->attribute;
$tempHtmlOpts = array();
CHtml::resolveNameID($this->model, $attr, $tempHtmlOpts);
$id = $tempHtmlOpts['id'];
$this->_fieldID = $id;
$this->_saveID = $id . '_save';
$this->_lookupID = $id . '_lookup';
$related = $this->model->{$this->relName};
// get the related record
$value = CHtml::resolveValue($this->model, $this->attribute);
$this->_display = !empty($value) ? $related->{$this->displayAttr} : '';
// $this->_display=($value!==null ? $related->{$this->displayAttr} : ''); // nineinchnick comment #6809 handle zero as valid FK value. not sure works in all cases
if (!isset($this->options['minLength'])) {
$this->options['minLength'] = 2;
}
if (!isset($this->options['maxHeight'])) {
$this->options['maxHeight'] = '100';
}
$this->htmlOptions['size'] = $this->autoCompleteLength;
// fix problem with Chrome 10 validating maxLength for the auto-complete field
$this->htmlOptions['maxlength'] = $this->autoCompleteLength;
// setup javascript to do the work
$this->options['create'] = "js:function(event, ui){\$(this).val('" . addslashes($this->_display) . "');}";
// show initial display value
// after user picks from list, save the ID in model/attr field, and Value in _save field for redisplay
$this->options['select'] = "js:function(event, ui){\$('#" . $this->_fieldID . "').val(ui.item.id);\$('#" . $this->_saveID . "').val(ui.item.value);}";
// when the autoComplete field loses focus, refresh the field with current value of _save
// this is either the previous value if user didn't pick anything; or the new value if they did
$this->htmlOptions['onblur'] = "\$(this).val(\$('#" . $this->_saveID . "').val());";
}
示例15: run
public function run()
{
// REGISTER JS SCRIPT
$cs = Yii::app()->clientScript;
$cs->registerScriptFile($this->_baseUrl . '/jquery.tipsy.js');
// REGISTER CSS
$cs->registerCssFile($this->_baseUrl . '/css/tipsy.css');
// LOOP THROUGH ITEMS
$items = $this->items;
$scriptList = array();
foreach ($items as $item) {
$params = array();
$htmlOptions = isset($item['htmlOptions']) ? $item['htmlOptions'] : array();
if (is_array($item['id'])) {
$model = $item['id']['model'];
$attribute = $item['id']['attribute'];
CHtml::resolveNameID($model, $attribute, $htmlOptions);
$tipsyID = '[name="' . $htmlOptions['name'] . '"]';
} else {
$tipsyID = $item['id'];
}
// OPTION: delayIn
if (isset($this->delayIn)) {
$params['delayIn'] = $this->delayIn;
} else {
$params['delayIn'] = 50;
//DEFAULT
}
if (isset($item['delayIn'])) {
$params['delayIn'] = $item['delayIn'];
}
// OPTION: delayOut
if (isset($this->delayOut)) {
$params['delayOut'] = $this->delayOut;
} else {
$params['delayOut'] = 50;
//DEFAULT
}
if (isset($item['delayOut'])) {
$params['delayOut'] = $item['delayOut'];
}
// OPTION: fade
if (isset($this->fade)) {
$params['fade'] = $this->fade;
}
if (isset($item['fade'])) {
$params['fade'] = $item['fade'];
}
// OPTION: fallback
if (isset($this->fallback)) {
$params['fallback'] = $this->fallback;
}
if (isset($item['fallback'])) {
$params['fallback'] = $item['fallback'];
}
// OPTION: gravity
if (isset($this->gravity)) {
$params['gravity'] = $this->gravity;
}
if (isset($item['gravity'])) {
$params['gravity'] = $item['gravity'];
}
// OPTION: html
if (isset($this->html)) {
$params['html'] = $this->html;
}
if (isset($item['html'])) {
$params['html'] = $item['html'];
}
// OPTION: offset
if (isset($this->offset)) {
$params['offset'] = $this->offset;
}
if (isset($item['offset'])) {
$params['offset'] = $item['offset'];
}
// OPTION: opacity
if (isset($this->opacity)) {
$params['opacity'] = $this->opacity;
} else {
$params['opacity'] = '0.8';
//DEFAULT
}
if (isset($item['opacity'])) {
$params['opacity'] = $item['opacity'];
}
// OPTION: title
if (isset($this->title)) {
$params['title'] = $this->title;
}
if (isset($item['title'])) {
$params['title'] = $item['title'];
}
// OPTION: trigger
if (isset($this->trigger)) {
$params['trigger'] = $this->trigger;
} else {
$params['trigger'] = 'hover';
//DEFAULT
}
//.........这里部分代码省略.........