Joomla에서 내 자신의 플러그인을 만들고 있는데 다중 선택 목록을 기사에 추가하고 싶습니다. 또한 기본적으로 일부 옵션을 선택해야합니다. 다음은 내 코드입니다.Joomla!에서 여러 옵션을 선택한 다중 선택 목록! plugin
public function onContentPrepareForm($form, $data)
{
if (!($form instanceof JForm))
{
$this->_subject->setError('JERROR_NOT_A_FORM');
return false;
}
$id = $data->id;
$catid = $data->catid;
$db = JFactory::getDBO();
$query = "SELECT ID, title FROM #__content WHERE catid = '" . SUBTOPIC_CATEGORY_ID . "'";
$db->setQuery($query);
$resultArray = $db->loadAssocList();
$optionsString = '';
foreach($resultArray as $result)
{
$optionsString .= '<option value="' . $result['ID'] . '"> ' . $result['title'] . '</option>';
}
if(isset($id) && isset($catid) && $catid == TOPIC_CATEGORY_ID)
{
$query = "SELECT subtopic FROM #__empd_topic WHERE ID = '$id'";
$db->setQuery($query);
$subtopicArray = $db->loadRow();
}
$xmlText = '<?xml version="1.0" encoding="utf-8"?>
<form>
<fields name="subtopic" label="subtopic">
<fieldset name="subtopic" label="subtopic">
<field
name="subtopic"
type="list"
id="subtopic"
multiple ="true"
label = "subtopic"
message = "Message"
>' . $optionsString . '</field>
</fieldset>
</fields>
</form>';
$xmlObj = new SimpleXMLElement($xmlText);
$form->setField($xmlObj);
return true;
}
이제 XML의 <field>
노드에 대한 기본 속성이 있지만 그것은 단지 하나의 값을 가질 수 있고 나는 또한 XML에 <option>
노드 내에서 selected="selected"
을 시도했지만 작동하지 않습니다. xml 목록 here에 대한 참조를 얻을 수 있습니다. 이 같은 문자열에 기본 값을 추가
을 탈출해야 [링크] (http://www.w3schools.com/xml/xml_attributes.asp) 우리는 여러 가질 수 없습니다 xml 특성에 대한 값. 심지어 요소 내에도을 시도했는데 작동하지 않았습니다. – mantish