開發一個 Model-View-Controller 元件/新增一個選單類型到前台

From Joomla! Documentation

< J3.x:Developing an MVC Component
This page is a translated version of the page J3.x:Developing an MVC Component/Adding a menu type to the site part and the translation is 56% complete.
Other languages:
Deutsch • ‎English • ‎Nederlands • ‎español • ‎français • ‎العربية • ‎中文(台灣)‎
開發一個 Model-View-Controller 元件










  1. 新增 ACL



  1. 新增一個圖片
  2. 新增一個 map
  3. 新增 AJAX
  4. 新增一個別名


  1. 新增一個 model
  2. 新增關聯
  3. 新增回存
  4. 新增排序
  5. 新增階層
  6. 新增版本控制
  7. 新增標籤
  8. 新增存取權限
  9. 新增批次作業
  10. 新增快取
  11. 新增 Feed


  1. 新增客製化欄位
  2. Upgrading to Joomla4

這是一系列的多篇文章,旨在介紹如何開發一個 Joomla! VersionJoomla 3.x Model-View-Controller 元件



  • You can follow the steps below to add a menu item to the Hello World! component, or you can directly download the archive

把 Hello World 加到選單項目

In this article we will cover how to add a menu item to a basic Joomla! component. For this example we will be continuing our work on the Hello World! component.

There are several ways to update a Joomla! component. As with the last tutorial, we will focus option 2.

1 手動新增檔案到 <path_to_joomla>/
2 Update using the Joomla! Extension Manager and the original directory, non-compressed, used for the component install
3 Update using the Joomla! Extension Manager and an Update Server

To add a menu item you will need to navigate to com_helloworld, which is the original directory we made for our component. You must use the updated directory structure from the last tutorial. Using your preferred file manager, create or update the following files; as you create or update the files, add the source code for each file which is found in File Details.

1 建立: default.xml <path_to_com_helloworld/site/views/helloworld/tmpl/default.xml
2 更新: helloworld.xml <path_to_com_helloworld/helloworld.xml

更新 Hello World! 元件

To update the Hello World! Component in the Joomla! website, please follow the same steps for the original installation.

After the component has been updated, we will be able to add a Menu Item to it. This will allow us to access our component a menu rather than having to remember what to type into the address bar. We'll do this using the Menu Manager of 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.
  • Add a new menu item by clicking on Menu    <existing menu>    Add New Menu Item. A new screen will appear.
  • In the "Menu Title" field, enter "Hello World!"
  • In the "Menu Type" field, click on the "Select" button and choose Hello World!    Hello World from the selection screen.
  • 點擊「儲存並關閉」

You should now be able to access the component through the menu that you just created.



<?xml version="1.0" encoding="utf-8"?>


<?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>
	<copyright>Copyright Info</copyright>
	<license>License Info</license>
	<!--  The version string is recorded in the components table -->
	<!-- 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 -->
			<schemapath type="mysql">sql/updates/mysql</schemapath>

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

		<!-- 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 -->
			<!-- SQL files section -->




Note - For the moment the strings won't be translated in the administrator interface. We will see in a later article how translation is performed.






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 避免網站伺服器列出路徑檔案內容
4 site/controller.php file representing the controller
5 site/views/index.html 避免網站伺服器列出路徑檔案內容
6 site/views/helloworld/index.html 避免網站伺服器列出路徑檔案內容
7 site/views/helloworld/view.html.php file representing the view
8 site/views/helloworld/tmpl/index.html 避免網站伺服器列出路徑檔案內容
9 site/views/helloworld/tmpl/default.php 預設的 view
10 site/views/helloworld/tmpl/default.xml file that adds menu item
11 admin/index.html 避免網站伺服器列出路徑檔案內容
12 admin/helloworld.php this is the administrator entry point to the Hello World! component
13 admin/sql/index.html 避免網站伺服器列出路徑檔案內容
14 admin/sql/updates/index.html 避免網站伺服器列出路徑檔案內容
15 admin/sql/updates/mysql/index.html 避免網站伺服器列出路徑檔案內容
16 admin/sql/updates/mysql/0.0.1.sql file allowing to initialise schema version of the com_helloworld component.