給視圖的某個佈局的XML描述文件中,增加自定義參數

62 篇文章 0 订阅
44 篇文章 0 订阅

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:

com_content


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':


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:

basic-parame


And the advanced section contains:


advanced-param


this generates:


advanced-html-output


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?


param-in-db


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');


param-object-in-jdump


add lines:

$rank_matchDay	= $params->get('rank_matchday');
dump($rank_matchDay, 'rank');


get-added-param-value

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" />


remove-old-para


and we don't need this JElement file:

removed-element



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
}







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值