J3.x

建立一個簡單的模組/新增自動更新

From Joomla! Documentation

< J3.x:Creating a simple module
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
This page is a translated version of the page J3.x:Creating a simple module/Adding Auto Update and the translation is 63% complete.
Other languages:
Bahasa Indonesia • ‎English • ‎Nederlands • ‎español • ‎français • ‎português • ‎中文(台灣)‎
Joomla! 
3.x
教學
建立一個簡單的模組

這一系列的文章介紹如何 建立一個 Joomla! 模組 版本 Joomla 3.x。您可以依序瀏覽文章。

讓我們從簡介開始,您可以使用底下的導覽按鈕來瀏覽文章,或是右側的方塊中的連結(列出所有的文章)。 您可以觀看 2 部和本教學相關的影片,基本 Joomla 模組開發影片教學 1 and 基本 Joomla 模組開發影片教學 2.




這個部分的教學會協助您建立一個更新伺服器,讓您的模組可以應用 Joomla 管理後台中的一鍵更新。

導言 & 預先閱讀

首先要閱讀使用 Joomla 2.5 管理元件 - Part 1 說明 to give an idea of how the upgrade process works in Joomla. Whilst written for 2.5 the process hasn't changed for Joomla 3.x。也請閱讀 開發一個上傳伺服器 - 這是我們在這一個教學文件中會使用的。.

Remember that sql update file we mentioned in the Using the database section? That will be used to update our database still. Whilst a new zipped version of our module will be used to update all the php files. To keep this simple for now we will update the files and sql database without any checks for Joomla version and the version of the module that is currently installed (it is recommended these are used in a production module).

更新模組

更新模組唯一的方法,是將更新伺服器資訊加到 xml 檔案。

<updateservers>
	<server type="extension" name="Helloworld" priority="1">http://www.example.com/helloworld_update.xml</server>
</updateservers>

Joomla! 會搜尋 http://www.example.com/helloworld_update.xml 中的更新資訊,如擴充套件管理選項中的頻率。

建立更新

So now that Joomla is searching for updates to our extension - lets create one to test out our process.

Create a copy of the module as it is now. Then lets update the version number to 1.0.1, and also we'll add something into our Update SQL file - in this case an extra German Language file.

<version>1.0.1</version>
INSERT INTO `#__helloworld` (`hello`, `lang`) VALUES ('Hallo Welt', 'de-DE');

Note we can also edit any of our php files - all the existing php files will be overridden by the ones in the update file (Note: This is the reason why core hacks of any extension are discouraged - they will be lost on the extension update).

Now we must create the xml file at http://www.example.com/helloworld_update.xml to let Joomla know an update is available.

<updates>
	<update>
		<name>Helloworld</name>
		<description>This is mod_helloworld 1.0.1</description>
		<element>mod_helloworld</element>
		<type>module</type>
		<version>1.0.1</version>
		<downloads>
			<downloadurl type="full" format="zip">http://www.example.com/mod_helloworld_101.zip</downloadurl>
		</downloads>
		<maintainer>Joomla</maintainer>
		<maintainerurl>http://www.example.com</maintainerurl>
		<targetplatform name="joomla" version="3.6"/>
		<client>site</client>
	</update>
</updates>

where http://www.example.com/mod_helloworld_101.zip is the zip of our newly created update. If you now log into the backend of Joomla you should now see in the control panel that an automatic update is available (if not you may need to purge your cache in the update section of the extension manager). Simply click update and you'll find your module has been updated to version 1.0.1.

Note: Note that the update tag in this case is specific for Joomla Version 3.6 and the update will not be recognized by an earlier or later version of Joomla. See the section on Deploying an Update Server for details on specifying the update and importantly the targetplatform tags.

Commercial Modules

Note that in our files we have linked to the extensions updates xml file. And from that xml file we have a location for the zip of the module. This means that if someone were to track this backwards they could find the physical source of your modules zip file (and make it available/use it after a subscription has expired etc.). For this reason generally commercial modules do not contain automatic updates (although they often will inform you of updates in some alternative way).

結論

更新 Joomla 模組是相當容易的,無論是對用戶或是開發者而言。自從Joomla! 3.1 起,應該要被當成標準化的作業。