As we discussed previously, in Joomla!, a component can have several views, and one certain view can have multiple layouts. Each layout has a php file, with an XML description file which has exactly the same name.
Like:
We will take the component 'com_content' as an example in the following investigation.
XML Description file:
Let's take a close look at 'blog.xml':
So far in our XML description file, the node 'params' is empty, because we generate all the parameters' value list by backend's JElement.
According to blog.xml, these parameters possible values can be specified just within this desc XML file, it supports different type of parameters:
radio;
text;
spacer,
The corresponding generated HTML panel:
And the advanced section contains:
this generates:
And we make a guess that: 'list' is a valid type in 'param' node,
Now we modify file: '/components/com_joomsport/views/rankinglist/tmpl/default.xml'
Action
Add a list type parameter to 'param' node:
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<layout title="默認佈局">
<message>
<![CDATA[成績龍虎榜默認佈局]]>
</message>
</layout>
<state>
<name>成績龍虎榜默認佈局</name>
<description>成績龍虎榜默認佈局</description>
<url addpath="/administrator/components/com_joomsport/elements">
<param name="gr_id" type="season" default="0" label="Select Group" description="Group" />
<param name="md_id" type="matchday" default="0" label="Select MatchDay" description="MatchDay" />
<param name="sid" type="season" default="0" label="Select Season" description="Season" />
<param name="rankseason" type="rankingterm" default="0" label="Select Ranking Type" description="Ranking Type" />
</url>
<params>
<param name="rank_matchday" type="list" default="0" label="Rank MatchDay" description="Rank list for which matchDay">
<option value="0">Select RankType</option>
<option value="1">聯賽盃第一、二循環</option>
<option value="2">聯賽盃總成績</option>
<option value="3">主席盃、碟及盾</option>
</param>
</params>
</state>
</metadata>
After we editing the menu item and save it at CMS panel, where does the parameter go to?
Now, the question is how to use it?
Paste these lines into the controller php of view[rankinglist]:
global $mainframe;
$params = clone($mainframe->getParams('com_joomsport'));
dump($params, 'params');
add lines:
$rank_matchDay = $params->get('rank_matchday');
dump($rank_matchDay, 'rank');
It works!!!
Clean the dated codes:
Replace:
$ranktype = JRequest::getVar( 'rankseason', 0, '', 'int' );
with:
global $mainframe;
$params = clone($mainframe->getParams('com_joomsport'));
$ranktype = $params->get('rank_matchday');
remove line in the XML:
<param name="rankseason" type="rankingterm" default="0" label="Select Ranking Type" description="Ranking Type" />
and we don't need this JElement file:
Now go to /administrator/components/com_joomsport/admin.joomsport.php
remove function 'BL_RankingSeason_Menu':
case 'rankseason_menu': BL_RankingSeason_Menu($option); break;
function BL_RankingSeason_Menu($option)
{
$RankingTerms = array(
1=>"聯賽盃第一、二循環",
2=>"聯賽盃總成績",
3=>"主席盃、碟及盾"
);
$row = array();
foreach($RankingTerms as $key=>$value)
{
$term = new stdClass;
$term->id = $key;
$term->name = $value;
$row[] = $term;
}
joomsport_html::bl_RankingSeasonMenu($row, $option);
}
go to file /administrator/components/com_joomsport/admin.joomsport.html.php
remove function that output the HTML markups for the value table:
function bl_RankingSeasonMenu( $rows, $option )
{
$jsf = JRequest::getVar('function','jSelectArticle','','string');
JHTML::_('behavior.tooltip');
?>
<table class="adminlist">
<thead>
<tr>
<th width="2%" align="left">
<?php echo JText::_( 'Id' ); ?>
</th>
<th class="title">
<?php echo JText::_( 'Name' ); ?>
</th>
</tr>
</thead>
<tbody>
<?php
$k = 0;
if( count( $rows ) )
{
for ($i=0, $n=count( $rows ); $i < $n; $i++)
{
$row = $rows[$i];
JFilterOutput::objectHtmlSafe($row);
?>
<tr class="<?php echo "row$k"; ?>">
<td>
<?php echo $i+1; ?>
</td>
<td>
<a href="javascript:window.parent.<?php echo $jsf;?>('<?php echo $row->id?>', '<?php echo htmlspecialchars($row->name, ENT_QUOTES, 'UTF-8')?>', 'rankseason');"><?php echo $row->name; ?></a>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<?php
}