J3.x:开发一个MVC组件/开发一个基础组件
From Joomla! Documentation
< J3.x:Developing an MVC Component
Articles in This Series
- Introduction
- Developing a Basic Component
- Adding a View to the Site Part
- Adding a Menu Type to the Site Part
- Adding a Model to the Site Part
- Adding a Variable Request in the Menu Type
- Using the Database
- Basic Backend
- Adding Language Management
- Adding Backend Actions
- Adding Decorations to the Backend
- Adding Verifications
- Adding Categories
- Adding Configuration
- Adding ACL
- Adding an Install/Uninstall/Update Script File
- Adding a Frontend Form
- Adding an Image
- Adding a Map
- Adding AJAX
- Adding an Alias
- Using the Language Filter Facility
- Adding a Modal
- Adding Associations
- Adding Checkout
- Adding Ordering
- Adding Levels
- Adding Versioning
- Adding Tags
- Adding Access
- Adding a Batch Process
- Adding Cache
- Adding a Feed
- Adding an Update Server
- Adding Custom Fields
- Upgrading to Joomla4
This is a multiple-article series of tutorials on how to develop a Model-View-Controller Component for Joomla! Version.
Begin with the Introduction, and navigate the articles in this series by using the navigation button at the bottom or the box to the right (the Articles in this series).
Notes
本教程是为Joomla! 3.x开发组件的一部分. You are encouraged to read the previous parts of the tutorial before reading this.
如果你已经在使用Joomla!在阅读本章前,你应该有印象,扩展的安装使用压缩文件包,里面包含所需的安装文件或卸载所用文件。
您可以按照下面的步骤来创建Hello World! 组件, 或者你可以下载这个组件包进行参考学习 附件
这里有一些幻灯片文档介绍如何创建基本Joomla !组件
Joomla! 基本组件帮助
Joomla! 高级组件帮助
There are also a number of videos which accompany steps in the tutorial, beginning with
Step 1, Developing a Basic Component and you can access the slides which are used in the series of video presentations at Slides.
Important! Around version 3.8 the Joomla developers started changing the naming of Joomla classes and where they were stored in the directory structure. Many of the tutorial steps and videos refer to the old naming convention. To find the equivalent new class and where it's stored, look in your libraries/classmap.php file.
如何图案家一个组件到Joomla
在本文中,我们将介绍如何创建和安装一个基本的Joomla !组件。对于这个示例,我们将使用Hello World !组件。
开始,你必须使用一个文件编辑器去创建一个目录用于这个组件. 这个目录的位置比较随意, 只要不在joomla的安装目录即可. 例如我们创建一个叫com_helloworld的目录,当然你也可以随便为这个目录起名.
接下来, 在这个目录中,我们需要创建一些文件. 使用你擅长的文件编辑器, 创建以下文件; 将你创建的文件, 添加每个文件的源代码中找到 文件说明.
1 | helloworld.xml | 这是一个XML 文件告诉 Joomla! 如何安装你的组件 |
2 | site/helloworld.php | 这是网站入口点去使用Hello World!组件 |
3 | site/index.html | 预防来自清单目录内容的web服务器 |
4 | admin/index.html | 预防来自清单目录内容的web服务器 |
5 | admin/helloworld.php | 这是惯例入口进入 Hello World! 组件 |
6 | admin/sql/index.html | 预防来自列表目录内容的web服务器 |
7 | admin/sql/updates/index.html | 预防来自列表目录内容的web服务器 |
8 | admin/sql/updates/mysql/index.html | 预防来自列表目录内容的web服务器 |
9 | admin/sql/updates/mysql/0.0.1.sql | 文件允许去预设一个版本信息为 com_helloworld组件. |
安装Hello World!组件
使用你的文件编辑器,创建一个 .zip文件,里面包括这个组件目录,例如名字可能是这样 com_helloworld.zip, 再说一遍,这个文件可以起任何名字
现在我们去安装Hello World!组件. 有两种方法可以做到这一点, both are covered in 安装一个扩展. 在这里我们将介绍该方法的扩展管理器使用Joomla !
- Using your preferred web browser, navigate to the Administrator panel of your Joomla! site. The address would be <yoursite>/joomla/administrator/index.php. For this example we will navigate to localhost/joomla/administrator/index.php.
- Click Extensions → Manage → Install → Upload Package File → Choose File
- Navigate and Select File
- Click Upload & Install
Note - You should see a message letting you know if the installation succeeded or failed.
You can test this basic function of the component by entering the Hello World! page for the site and administrator portions of your Joomla! website.
- Using your preferred web browser, navigate to the Hello World! component page located on the site portion of your website. The address would be <yoursite>/joomla/index.php?option=com_helloworld. For this example we will navigate to localhost/joomla/index.php?option=com_helloworld.
- Using your preferred web browser, navigate to the Hello World! component page located on the administrator portion of your website. The address would be <yoursite>/joomla/administrator/index.php?option=com_helloworld. For this example we will navigate to localhost/joomla/administrator/index.php?option=com_helloworld.
You can also notice that the Hello World! component is visible in the administrator site of your Joomla installation under the Components menu.
File Details
admin/sql/updates/mysql/0.0.1.sql is an empty file allowing to initialise schema version of the com_helloworld component.
helloworld.xml
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.0" method="upgrade">
<name>Hello World!</name>
<!-- The following elements are optional and free of formatting constraints -->
<creationDate>January 2018</creationDate>
<author>John Doe</author>
<authorEmail>john.doe@example.org</authorEmail>
<authorUrl>http://www.example.org</authorUrl>
<copyright>Copyright Info</copyright>
<license>License Info</license>
<!-- The version string is recorded in the components table -->
<version>0.0.1</version>
<!-- The description is optional and defaults to the name -->
<description>Description of the Hello World component ...</description>
<update> <!-- Runs on update; New since J2.5 -->
<schemas>
<schemapath type="mysql">sql/updates/mysql</schemapath>
</schemas>
</update>
<!-- Site Main File Copy Section -->
<!-- Note the folder attribute: This attribute describes the folder
to copy FROM in the package to install therefore files copied
in this section are copied from /site/ in the package -->
<files folder="site">
<filename>index.html</filename>
<filename>helloworld.php</filename>
</files>
<administration>
<!-- Administration Menu Section -->
<menu link='index.php?option=com_helloworld'>Hello World!</menu>
<!-- Administration Main File Copy Section -->
<!-- Note the folder attribute: This attribute describes the folder
to copy FROM in the package to install therefore files copied
in this section are copied from /admin/ in the package -->
<files folder="admin">
<!-- Admin Main File Copy Section -->
<filename>index.html</filename>
<filename>helloworld.php</filename>
<!-- SQL files section -->
<folder>sql</folder>
</files>
</administration>
</extension>
site/helloworld.php
Hello World
admin/helloworld.php
Hello World administration
index.html
common to all folders
<html><body bgcolor="#FFFFFF"></body></html>
Component Contents
At this point in the tutorial, your component should contain the following files:
1 | helloworld.xml | this is an XML (manifest) file that tells Joomla! how to install our component. |
2 | site/helloworld.php | this is the site entry point to the Hello World! component |
3 | site/index.html | prevents web server from listing directory content |
4 | admin/index.html | prevents web server from listing directory content |
5 | admin/helloworld.php | this is the administrator entry point to the Hello World! component |
6 | admin/sql/index.html | prevents web server from listing directory content |
7 | admin/sql/updates/index.html | prevents web server from listing directory content |
8 | admin/sql/updates/mysql/index.html | prevents web server from listing directory content |
9 | admin/sql/updates/mysql/0.0.1.sql | file allowing to initialise schema version of the com_helloworld component. |
An updated git repository following along this tutorial is available @ https://github.com/Stevec4/Joomla-HelloWorld for any code descprepancies or edits please make a pull request.