本文整理汇总了PHP中CHtml::getIdByName方法的典型用法代码示例。如果您正苦于以下问题:PHP CHtml::getIdByName方法的具体用法?PHP CHtml::getIdByName怎么用?PHP CHtml::getIdByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CHtml
的用法示例。
在下文中一共展示了CHtml::getIdByName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: labelEx
/**
* @inheritDoc
*/
public function labelEx($model, $attribute, $htmlOptions = array())
{
if (!$this->qualifyNames && !isset($htmlOptions['for'])) {
$htmlOptions['for'] = \CHtml::getIdByName($attribute);
}
return parent::labelEx($model, $attribute, $htmlOptions);
}
示例2: testRun_FieldRendering
/**
* @param array $widgetOptions Widget options.
* @covers ::run
* @dataProvider testRun_FieldRendering_Provider
*/
public function testRun_FieldRendering($widgetOptions)
{
$widget = $this->makeWidget();
foreach ($widgetOptions as $option => $value) {
$widget->{$option} = $value;
}
$widgetOutput = $this->runAndCapture($widget);
$value = isset($widgetOptions['model']) ? $widgetOptions['model']->login : $widgetOptions['value'];
if (isset($widgetOptions['model'])) {
$name = CHtml::activeName($widgetOptions['model'], $widgetOptions['attribute']);
} elseif (isset($widgetOptions['htmlOptions']['name'])) {
$name = $widgetOptions['htmlOptions']['name'];
} else {
$name = $widgetOptions['name'];
}
if (isset($widgetOptions['model'])) {
$id = CHtml::activeId($widgetOptions['model'], $widgetOptions['attribute']);
} elseif (isset($widgetOptions['htmlOptions']['id'])) {
$id = $widgetOptions['htmlOptions']['id'];
} else {
$id = CHtml::getIdByName($widgetOptions['name']);
}
if ($widgetOptions['type'] == Select2::TYPE_TEXT) {
$this->assertTag(['tag' => 'input', 'attributes' => ['type' => 'text', 'name' => $name, 'id' => $id, 'value' => $value, 'class' => 'baz']], $widgetOutput);
} else {
$this->assertTag(['tag' => 'select', 'attributes' => ['name' => $name, 'id' => $id, 'class' => 'baz']], $widgetOutput);
$this->assertTag(['tag' => 'option', 'parent' => ['tag' => 'select'], 'attributes' => ['selected' => 'selected', 'value' => $value]], $widgetOutput);
}
}
示例3: autoComplete
function autoComplete($name, $complete_view, $id = '', $value = '')
{
$url = is_array($complete_view) ? $complete_view : array($complete_view);
$dom_id = CHtml::getIdByName($name);
echo CHtml::hiddenField($name, $id, array('id' => $dom_id));
$this->widget('zii.widgets.jui.CJuiAutoComplete', array('name' => $dom_id . '_autocomplete', 'sourceUrl' => $url, 'options' => array('select' => "js:function(event, ui) {\n \$('#{$dom_id}').val(ui.item.id);\n }"), 'value' => $value));
}
示例4: radioButtonList
public static function radioButtonList($name, $select, $data, $htmlOptions = array())
{
$template = isset($htmlOptions['template']) ? $htmlOptions['template'] : '{input} {label}';
$separator = isset($htmlOptions['separator']) ? $htmlOptions['separator'] : "<br/>\n";
unset($htmlOptions['template'], $htmlOptions['separator']);
$labelOptions = isset($htmlOptions['labelOptions']) ? $htmlOptions['labelOptions'] : array();
unset($htmlOptions['labelOptions']);
$items = array();
$baseID = CHtml::getIdByName($name);
$id = 0;
foreach ($data as $value => $item) {
$checked = !strcmp($value, $select);
$htmlOptions['value'] = $value;
$labelOptions['id'] = $baseID . '_label_' . $id;
$htmlOptions['id'] = $baseID . '_' . $id++;
$labelOptions['title'] = $item['title'];
$htmlOptions['class'] = 'ui-icon ui-state-default ' . $item['class'];
$option = CHtml::radioButton($name, $checked, $htmlOptions);
if (!empty($item['icon'])) {
$item['caption'] = '<span style="float:left;" class="ui-icon ' . $item['icon'] . '"> ' . $item['caption'] . '</span>' . $item['caption'];
}
$label = CHtml::label($item['caption'], $htmlOptions['id'], $labelOptions);
$items[] = strtr($template, array('{input}' => $option, '{label}' => $label));
}
return CHtml::tag('span', array('id' => $baseID), implode($separator, $items));
}
示例5: run
/**
* Runs the widget.
* This method registers all needed client scripts and renders
* the multiple file uploader.
*/
public function run()
{
if ($this->name !== null) {
$name = $this->name;
} else {
if (isset($this->htmlOptions['name'])) {
$name = $this->htmlOptions['name'];
} else {
throw new CException(Yii::t('yii', 'CMultiFileUpload.name is required.'));
}
}
if (substr($name, -2) !== '[]') {
$name .= '[]';
}
if (($id = $this->getId(false)) === null) {
if (isset($this->htmlOptions['id'])) {
$id = $this->htmlOptions['id'];
} else {
$id = CHtml::getIdByName($name);
}
}
$this->htmlOptions['id'] = $id;
$this->registerClientScript();
echo CHtml::fileField($name, '', $this->htmlOptions);
}
示例6: labelEx
/**
* Renders an HTML label for a model attribute.
* @param CModel $parentModel the parent data model
* @param string $attributedPath the attribute or path to related model attribute
* @param array $htmlOptions additional HTML attributes.
* @return string the generated label tag
*/
public function labelEx($parentModel, $attributedPath, $htmlOptions = array())
{
list($model, $attribute, $htmlOptions) = self::resolveArgs($parentModel, $attributedPath, $htmlOptions);
$htmlOptions['for'] = CHtml::getIdByName($htmlOptions['name']);
if (!isset($htmlOptions['label']) && ($label = self::resolveLabel($parentModel, $attributedPath)) !== null) {
$htmlOptions['label'] = $label;
}
return parent::labelEx($model, $attribute, $htmlOptions);
}
示例7: init
public function init()
{
parent::init();
$this->paramLink = array('id_field' => CHtml::getIdByName($this->fieldId), 'multileSelect' => $this->multiSelect ? 1 : 0);
if (!$this->dialogZone) {
$this->idZone = array('id' => 'showJobDialog', 'class' => 'ajaxlink');
$this->updateZone = array('onclick' => '$("#jobDialog").dialog("open"); return false;', 'update' => '#jobDialog');
} else {
$this->paramLink['id_dialog'] = $this->dialogZone;
$this->idZone = array('id' => $this->dialogZone . "-show", 'class' => 'ajaxlink');
$this->updateZone = array('onclick' => '$("#jobDialog").dialog("open"); return false;', 'update' => '#dialog');
}
$this->link = $this->controller->createUrl('artist/popupList', $this->paramLink);
$this->htmlOptions['readonly'] = 'readonly';
}
示例8: run
public function run()
{
$cs = Yii::app()->getClientScript();
$textAreaOptions = $this->gettextareaOptions();
$textAreaOptions['name'] = CHtml::resolveName($this->model, $this->name);
$this->id = $textAreaOptions['id'] = CHtml::getIdByName($textAreaOptions['name']);
echo CHtml::activeTextArea($this->model, $this->name, $textAreaOptions);
$properties_string = CJavaScript::encode($this->getKeProperties());
$js = <<<EOF
KindEditor.ready(function(K) {
\tvar editor_{$this->id} = K.create('#{$this->id}',
{$properties_string}
\t);
});
EOF;
$cs->registerScript('KE' . $this->name, $js, CClientScript::POS_HEAD);
}
示例9: init
public function init()
{
parent::init();
$this->paramLink = array('id_field' => CHtml::getIdByName($this->fieldId), 'name_field' => CHtml::getIdByName($this->fieldName));
if (!$this->dialogZone) {
$this->idZone = array('id' => 'showJobDialog', 'class' => 'ajaxlink');
$this->updateZone = array('onclick' => '$("#jobDialog").dialog("open"); return false;', 'update' => '#jobDialog');
} else {
$this->paramLink['id_dialog'] = $this->dialogZone;
$this->idZone = array('id' => $this->dialogZone . "-show", 'class' => 'ajaxlink');
/*$this->updateZone = array(
'onclick'=>'$("#'.$this->dialogZone.'").dialog("open"); return false;',
'update'=>'#'.$this->dialogZone
);*/
$this->updateZone = array('onclick' => '$("#jobDialog").dialog("open"); return false;', 'update' => '#jobDialog');
//echo "<div id='$this->dialogZone'></div>";
}
$this->link = $this->controller->createUrl('artist/popupList', $this->paramLink);
$this->htmlOptions['readonly'] = 'readonly';
}
示例10: resolveNameID
/**
* Resolves name and ID of the input. Source property of the name and/or source property of the attribute
* could be customized by specifying first and/or second parameter accordingly.
* @param string $nameProperty class property name which holds element name to be used. This parameter
* is available since 1.1.14.
* @param string $attributeProperty class property name which holds model attribute name to be used. This
* parameter is available since 1.1.14.
* @return array name and ID of the input: array('name','id').
* @throws CException in case model and attribute property or name property cannot be resolved.
*/
protected function resolveNameID($nameProperty = 'name', $attributeProperty = 'attribute')
{
if ($this->{$nameProperty} !== null) {
$name = $this->{$nameProperty};
} elseif (isset($this->htmlOptions[$nameProperty])) {
$name = $this->htmlOptions[$nameProperty];
} elseif ($this->hasModel()) {
$name = CHtml::activeName($this->model, $this->{$attributeProperty});
} else {
throw new CException(Yii::t('zii', '{class} must specify "model" and "{attribute}" or "{name}" property values.', array('{class}' => get_class($this), '{attribute}' => $attributeProperty, '{name}' => $nameProperty)));
}
if (($id = $this->getId(false)) === null) {
if (isset($this->htmlOptions['id'])) {
$id = $this->htmlOptions['id'];
} else {
$id = CHtml::getIdByName($name);
}
}
return array($name, $id);
}
示例11: resolveNameID
/**
* @return array the name and the ID of the input.
* @throws \foundation\exception\InvalidConfigException
*/
protected function resolveNameID()
{
if ($this->name !== null) {
$name = $this->name;
} elseif (isset($this->htmlOptions['name'])) {
$name = $this->htmlOptions['name'];
} elseif ($this->hasModel()) {
$name = \CHtml::activeName($this->model, $this->attribute);
} else {
throw new InvalidConfigException(\Yii::t('yii', '{class} must specify "model" and "attribute" or "name" property values.', array('{class}' => get_class($this))));
}
if (($id = $this->getId(false)) === null) {
if (isset($this->htmlOptions['id'])) {
$id = $this->htmlOptions['id'];
} else {
$id = \CHtml::getIdByName($name);
}
}
return array($name, $id);
}
示例12: init
public function init()
{
parent::init();
$idTxt = CHtml::getIdByName($this->fieldName);
$idById = CHtml::getIdByName($this->fieldId);
Yii::app()->getClientScript()->registerCssFile(Yii::app()->theme->baseUrl . "/css/jquery.autocomplete.css");
Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . "/js/jquery.autocomplete.js");
$link = Yii::app()->createUrl("artist/autoComplete");
$script = <<<EOD
\t \$(document).ready(function() {
\t \t \$('#{$idTxt}').autocomplete('{$link}', {
\t\t\t\twidth: 260,
\t\t\t\tmatchContains: true,
\t\t\t\tmustMatch: true,
\t\t\t\tselectFirst: true
\t\t\t});
\t\t\t\$("#{$idTxt}").result(function(event, data, formatted) {
\t\t\t\t\$("#{$idTxt}").val(data[0]);
\t\t\t\t\$("#{$idById}").val(data[1]);
\t\t\t});
\t });
EOD;
Yii::app()->clientScript->registerScript("artist-auto", $script, CClientScript::POS_HEAD);
}
示例13: init
public function init()
{
$this->id = CHtml::getIdByName($this->name);
parent::init();
$this->publishAssets();
}
示例14: testGetIdByName
/**
* @dataProvider providerGetIdByName
*
* @param string $text
* @param string $assertion
*/
public function testGetIdByName($text, $assertion)
{
$this->assertEquals($assertion, CHtml::getIdByName($text));
}
示例15: resolveID
protected function resolveID($attr)
{
$name = CHtml::activeName($this->model, $attr);
$id = CHtml::getIdByName($name);
return $id;
}