xml在joomla表单中的应用详解分享_PHP
使用起来基本都有固定格式,在此不多说,这里主要说说xml在创建表单中的应用.表单的作用不言而喻,在模块配置里面有表单,组件里面也有表单,这里的配置里面的参数设置就是xml生成的表单,相对于通过直接建表单方便不少,这里通过编辑文章表单的使用过程来说,在使用之前,我们先来了解一下表单元素的类型,joomla提供了生成多种表单元素样式.
复制代码 代码如下:
//生成日历时间
//得到单元列表
//其他组件单元列表
//编辑器选择列表
//文件列表 html表示显示扩展名为html
//文件夹列表
//隐藏域
//密码
//单选
//单元选择
//水平线
//SQL生成列表
//文本框
//文本域无样式
//文本域有样式
//生成时区列表
上边就是提供的一些生成元素,但是如何使用呢,我们首先建立一个form.xml,在组件的models文件夹内
复制代码 代码如下:
这里只有一个隐藏元素其实我们可以建立更多的元素,就是上边的那些生成元素类型,当然还可以自定义,这里的addpath就是自定义元素类型,位置就是在组建的elements文件夹内,上边的是内置的,笔者在这里定义了如下类型
复制代码 代码如下:
//自定义控件
//数组转换成列表 不写下标从0开始
//生成是否单选
//上传控件
//数组复选
//无限分类 注意添加section父类为0
使用方法如上,元素的自定义文件在下载里面提供.接着我们在views文件夹下面你的视图文件夹内的view.html.php增加如下语句
复制代码 代码如下:
$form = new JParameter('',JPATH_COMPONENT.DS.'models'.DS.'form.xml');
$form->set('m1','默认值');
$html=$form->render('details', 'html'); //details是元素名数组
$this->assignRef('html',$html);
上边第二句就是赋值,把隐藏域赋值,相当于编辑里面取值,第三四句是把表单html输出到模版,details是元素名称数组名,生成的m1的name就是details[m1],接着就是form.php调用如下
复制代码 代码如下:
这样一个表单就生成了,相对于直接写表单元素,这种方法更容易修改风格或者内容,修改只需要改xml文件即可,在joomla2.5版本中,基本上都是通过这种方式实现的,不过变化比较大,xml文件写法大不相同,通过xml是可以调用其他组件里面表单元素的.
表单元素的这些类型在模版配置参数,模块参数都是可以使用的,特别是可以自己扩展表单元素的样式,你完全可以定义出其他样式类型,笔者定义了比较常用的几种但是内置没有提供的,比如数组转换列表,数组转换复选,无限分类等样式.这里的类型其实就是api的JElement类,里面的源文件可以参考libraries\joomla\html\parameter\element,这里自定义表单元素怎么写呢这里给个例子或者参考源文件就明白了,文件名custom.php,类型也就是custom了,调用方法
复制代码 代码如下:
// 自定义显示
//
defined('_JEXEC') or die('Restricted access');
class JElementCustom extends JElement{
var $_name = 'Custom';
function fetchElement($name, $value, &$node, $control_name) {
$html=自定义
EOF;
return $html;
}
}
好了,就不多讲了,其实这只是一种建立表单的方法,如果你不喜欢,完全可以使用写表单元素,不过既然joomla提供了这些我们为什么不用呢?
下载自定义元素: elements_jb51.rar

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Can XML files be opened with PPT? XML, Extensible Markup Language (Extensible Markup Language), is a universal markup language that is widely used in data exchange and data storage. Compared with HTML, XML is more flexible and can define its own tags and data structures, making the storage and exchange of data more convenient and unified. PPT, or PowerPoint, is a software developed by Microsoft for creating presentations. It provides a comprehensive way of

Using Python to merge and deduplicate XML data XML (eXtensibleMarkupLanguage) is a markup language used to store and transmit data. When processing XML data, sometimes we need to merge multiple XML files into one, or remove duplicate data. This article will introduce how to use Python to implement XML data merging and deduplication, and give corresponding code examples. 1. XML data merging When we have multiple XML files, we need to merge them

Convert XML data in Python to CSV format XML (ExtensibleMarkupLanguage) is an extensible markup language commonly used for data storage and transmission. CSV (CommaSeparatedValues) is a comma-delimited text file format commonly used for data import and export. When processing data, sometimes it is necessary to convert XML data to CSV format for easy analysis and processing. Python is a powerful

Implementing filtering and sorting of XML data using Python Introduction: XML is a commonly used data exchange format that stores data in the form of tags and attributes. When processing XML data, we often need to filter and sort the data. Python provides many useful tools and libraries to process XML data. This article will introduce how to use Python to filter and sort XML data. Reading the XML file Before we begin, we need to read the XML file. Python has many XML processing libraries,

Importing XML data into the database using PHP Introduction: During development, we often need to import external data into the database for further processing and analysis. As a commonly used data exchange format, XML is often used to store and transmit structured data. This article will introduce how to use PHP to import XML data into a database. Step 1: Parse the XML file First, we need to parse the XML file and extract the required data. PHP provides several ways to parse XML, the most commonly used of which is using Simple

Python implements conversion between XML and JSON Introduction: In the daily development process, we often need to convert data between different formats. XML and JSON are common data exchange formats. In Python, we can use various libraries to convert between XML and JSON. This article will introduce several commonly used methods, with code examples. 1. To convert XML to JSON in Python, we can use the xml.etree.ElementTree module

Handling Errors and Exceptions in XML Using Python XML is a commonly used data format used to store and represent structured data. When we use Python to process XML, sometimes we may encounter some errors and exceptions. In this article, I will introduce how to use Python to handle errors and exceptions in XML, and provide some sample code for reference. Use try-except statement to catch XML parsing errors When we use Python to parse XML, sometimes we may encounter some

Python parses special characters and escape sequences in XML XML (eXtensibleMarkupLanguage) is a commonly used data exchange format used to transfer and store data between different systems. When processing XML files, you often encounter situations that contain special characters and escape sequences, which may cause parsing errors or misinterpretation of the data. Therefore, when parsing XML files using Python, we need to understand how to handle these special characters and escape sequences. 1. Special characters and
