Иногда нужно, чтобы при переходе к компоненту через меню, учитывались параметры, например, id категории.
Это делается с помощью JElement.
Для раскладки default.php создадим default.xml файл в components\com_component\views\view_name\tmpl :
<?xml version="1.0" encoding="utf-8"?> <metadata> <layout title="Category Blog Layout"> <message> <![CDATA[CATEGORY BLOG LAYOUT DESC]]> </message> </layout> <state> <name>Category Blog Layout</name> <description>CATEGORY BLOG LAYOUT DESC</description> <url addpath="/administrator/components/COMPONENT_NAME/elements"> <param name="id" type="category" label="Category" description="Choose a category..." /> </url> <params> <param /> ... </params> <advanced> <param/> ... </advanced> </state> </metadata>
В файле /administrator/components/com_component/elements/category.php задается html для параметра id
Текстовый параметр:
function fetchElement( $name, $value, &$node, $control_name )
{
$class = $node->attributes( 'class' ) ? $node->attributes( 'class' ) : "text_area";
$return = '<input type="text"' .
'name="' . $control_name . '[' . $name . ']"' .
'id="' . $control_name . '[' . $name . ']"' .
'value="' . $value . '"' .
'class="' . $class . '" />';
return $return;
}
или список:
defined('_JEXEC') or die();
class JElementFiler extends JElement
{
var $_name = 'id';
function fetchElement($name, $value, &$node, $control_name) {
return JHTML::_('select.genericlist', $result, ''.$control_name.'['.$name.']', 'class="inputbox"', 'value', 'text', $value, $control_name.$name );
}
}
где
function fetchElement($name, $value, &$node, $control_name)
$name is the unique name of the parameter, from the name argument.
$value is the current value of the parameter.
$node is a JSimpleXMLElement object representing the <param> element.
$control_name is the parameter type from the type argument (eg. 'category' or 'newparm')