Difference between revisions of "Rvsjoen/tutorial/Developing an MVC Component/Part 13"
From Joomla! Documentation
< User:Rvsjoen | tutorial/Developing an MVC Component
Line 9: | Line 9: | ||
<span id="admin/sql/install.mysql.utf8.sql"> | <span id="admin/sql/install.mysql.utf8.sql"> | ||
'''<tt>admin/sql/install.mysql.utf8.sql</tt>''' | '''<tt>admin/sql/install.mysql.utf8.sql</tt>''' | ||
− | <source lang="sql" highlight=" | + | <source lang="sql" highlight="7"> |
+ | DROP TABLE IF EXISTS `#__helloworld`; | ||
+ | CREATE TABLE `#__helloworld` ( | ||
+ | `id` int(11) NOT NULL auto_increment, | ||
+ | `greeting` varchar(25) NOT NULL, | ||
+ | `catid` int(11) NOT NULL DEFAULT '0', | ||
+ | `params` TEXT NOT NULL DEFAULT '', | ||
+ | PRIMARY KEY (`id`) | ||
+ | ) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8; | ||
+ | |||
+ | INSERT INTO `#__helloworld` (`greeting`) VALUES | ||
+ | ('Hello World!'), | ||
+ | ('Good bye World!'); | ||
</source> | </source> | ||
</span> | </span> | ||
Line 25: | Line 37: | ||
'''<tt>admin/models/forms/helloworld.xml</tt>''' | '''<tt>admin/models/forms/helloworld.xml</tt>''' | ||
<source lang="xml"> | <source lang="xml"> | ||
− | + | <?xml version="1.0" encoding="utf-8"?> | |
+ | <form addrulepath="/administrator/components/com_helloworld/models/rules"> | ||
+ | <fieldset name="details"> | ||
+ | <field | ||
+ | name="id" | ||
+ | type="hidden" | ||
+ | /> | ||
+ | <field | ||
+ | name="greeting" | ||
+ | type="text" | ||
+ | label="COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_LABEL" | ||
+ | description="COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_DESC" | ||
+ | size="40" | ||
+ | class="inputbox validate-greeting" | ||
+ | validate="greeting" | ||
+ | required="true" | ||
+ | default="" | ||
+ | /> | ||
+ | <field | ||
+ | name="catid" | ||
+ | type="category" | ||
+ | extension="com_helloworld" | ||
+ | class="inputbox" | ||
+ | default="" | ||
+ | label="COM_HELLOWORLD_HELLOWORLD_FIELD_CATID_LABEL" | ||
+ | description="COM_HELLOWORLD_HELLOWORLD_FIELD_CATID_DESC" | ||
+ | required="true"> | ||
+ | <option value="0">JOPTION_SELECT_CATEGORY</option> | ||
+ | </field> | ||
+ | </fieldset> | ||
+ | <fields name="params"> | ||
+ | <fieldset name="params" label="JGLOBAL_FIELDSET_DISPLAY_OPTIONS"> | ||
+ | <field | ||
+ | name="show_category" | ||
+ | type="list" | ||
+ | label="COM_HELLOWORLD_HELLOWORLD_FIELD_SHOW_CATEGORY_LABEL" | ||
+ | description="COM_HELLOWORLD_HELLOWORLD_FIELD_SHOW_CATEGORY_DESC" | ||
+ | default=""> | ||
+ | <option value="">JGLOBAL_USE_GLOBAL</option> | ||
+ | <option value="0">JHIDE</option> | ||
+ | <option value="1">JSHOW</option> | ||
+ | </field> | ||
+ | </fieldset> | ||
+ | </fields> | ||
+ | </form> | ||
</source> | </source> | ||
</span> | </span> | ||
Line 36: | Line 92: | ||
'''<tt>admin/language/en-GB/en-GB.com_helloworld.ini</tt>''' | '''<tt>admin/language/en-GB/en-GB.com_helloworld.ini</tt>''' | ||
<source lang="ini"> | <source lang="ini"> | ||
− | + | COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_DESC="This message will be displayed" | |
+ | COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_LABEL="Message" | ||
+ | COM_HELLOWORLD_HELLOWORLD_HEADING_GREETING="Greeting" | ||
+ | COM_HELLOWORLD_HELLOWORLD_HEADING_ID="ID" | ||
+ | COM_HELLOWORLD_HELLOWORLD_DETAILS="Details" | ||
+ | COM_HELLOWORLD_MANAGER_HELLOWORLDS="HelloWorld manager" | ||
+ | COM_HELLOWORLD_MANAGER_HELLOWORLD_NEW="HelloWorld manager: New Message" | ||
+ | COM_HELLOWORLD_MANAGER_HELLOWORLD_EDIT="HelloWorld manager: Edit Message" | ||
+ | COM_HELLOWORLD_N_ITEMS_DELETED_1="One message deleted" | ||
+ | COM_HELLOWORLD_N_ITEMS_DELETED_MORE="%d messages deleted" | ||
+ | COM_HELLOWORLD_ADMINISTRATION="HelloWorld - Administration" | ||
+ | COM_HELLOWORLD_HELLOWORLD_CREATING="HelloWorld - Creating" | ||
+ | COM_HELLOWORLD_HELLOWORLD_EDITING="HelloWorld - Editing" | ||
+ | COM_HELLOWORLD_SUBMENU_MESSAGES="Messages" | ||
+ | COM_HELLOWORLD_SUBMENU_CATEGORIES="Categories" | ||
+ | COM_HELLOWORLD_HELLOWORLD_FIELD_CATID_DESC="The category the messages belongs to" | ||
+ | COM_HELLOWORLD_HELLOWORLD_FIELD_CATID_LABEL="Category" | ||
+ | COM_HELLOWORLD_ADMINISTRATION_CATEGORIES="HelloWorld - Categories" | ||
+ | COM_HELLOWORLD_CONFIGURATION="HelloWorld Configuration" | ||
+ | COM_HELLOWORLD_CONFIG_GREETING_SETTINGS_LABEL="Messages settings" | ||
+ | COM_HELLOWORLD_CONFIG_GREETING_SETTINGS_DESC="Settings that will be applied to all messages by default" | ||
+ | COM_HELLOWORLD_HELLOWORLD_FIELD_SHOW_CATEGORY_LABEL="Show category" | ||
+ | COM_HELLOWORLD_HELLOWORLD_FIELD_SHOW_CATEGORY_DESC="If set to Show, the title of the message’s category will show." | ||
</source> | </source> | ||
</span> | </span> |
Revision as of 09:53, 12 July 2011
Adding component options[edit]
Adding parameters to the database[edit]
In order to use the parameters in Joomla! we need to add a field to our table in the database.
With your favorite editor, modify the following file to look like this
admin/sql/install.mysql.utf8.sql
DROP TABLE IF EXISTS `#__helloworld`;
CREATE TABLE `#__helloworld` (
`id` int(11) NOT NULL auto_increment,
`greeting` varchar(25) NOT NULL,
`catid` int(11) NOT NULL DEFAULT '0',
`params` TEXT NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
INSERT INTO `#__helloworld` (`greeting`) VALUES
('Hello World!'),
('Good bye World!');
NOTE: You WILL need to completely uninstall and reinstall the component for these changes to take effect if you have any of the previous parts installed.
Update the form definition[edit]
We are going to have to modify our helloworld form in order to add a fieldset for the parameters
With your favorite editor, modify the following file to look like this
admin/models/forms/helloworld.xml
<?xml version="1.0" encoding="utf-8"?>
<form addrulepath="/administrator/components/com_helloworld/models/rules">
<fieldset name="details">
<field
name="id"
type="hidden"
/>
<field
name="greeting"
type="text"
label="COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_LABEL"
description="COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_DESC"
size="40"
class="inputbox validate-greeting"
validate="greeting"
required="true"
default=""
/>
<field
name="catid"
type="category"
extension="com_helloworld"
class="inputbox"
default=""
label="COM_HELLOWORLD_HELLOWORLD_FIELD_CATID_LABEL"
description="COM_HELLOWORLD_HELLOWORLD_FIELD_CATID_DESC"
required="true">
<option value="0">JOPTION_SELECT_CATEGORY</option>
</field>
</fieldset>
<fields name="params">
<fieldset name="params" label="JGLOBAL_FIELDSET_DISPLAY_OPTIONS">
<field
name="show_category"
type="list"
label="COM_HELLOWORLD_HELLOWORLD_FIELD_SHOW_CATEGORY_LABEL"
description="COM_HELLOWORLD_HELLOWORLD_FIELD_SHOW_CATEGORY_DESC"
default="">
<option value="">JGLOBAL_USE_GLOBAL</option>
<option value="0">JHIDE</option>
<option value="1">JSHOW</option>
</field>
</fieldset>
</fields>
</form>
Update the language files[edit]
With your favorite editor, modify the following files to look like this
admin/language/en-GB/en-GB.com_helloworld.ini
COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_DESC="This message will be displayed"
COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_LABEL="Message"
COM_HELLOWORLD_HELLOWORLD_HEADING_GREETING="Greeting"
COM_HELLOWORLD_HELLOWORLD_HEADING_ID="ID"
COM_HELLOWORLD_HELLOWORLD_DETAILS="Details"
COM_HELLOWORLD_MANAGER_HELLOWORLDS="HelloWorld manager"
COM_HELLOWORLD_MANAGER_HELLOWORLD_NEW="HelloWorld manager: New Message"
COM_HELLOWORLD_MANAGER_HELLOWORLD_EDIT="HelloWorld manager: Edit Message"
COM_HELLOWORLD_N_ITEMS_DELETED_1="One message deleted"
COM_HELLOWORLD_N_ITEMS_DELETED_MORE="%d messages deleted"
COM_HELLOWORLD_ADMINISTRATION="HelloWorld - Administration"
COM_HELLOWORLD_HELLOWORLD_CREATING="HelloWorld - Creating"
COM_HELLOWORLD_HELLOWORLD_EDITING="HelloWorld - Editing"
COM_HELLOWORLD_SUBMENU_MESSAGES="Messages"
COM_HELLOWORLD_SUBMENU_CATEGORIES="Categories"
COM_HELLOWORLD_HELLOWORLD_FIELD_CATID_DESC="The category the messages belongs to"
COM_HELLOWORLD_HELLOWORLD_FIELD_CATID_LABEL="Category"
COM_HELLOWORLD_ADMINISTRATION_CATEGORIES="HelloWorld - Categories"
COM_HELLOWORLD_CONFIGURATION="HelloWorld Configuration"
COM_HELLOWORLD_CONFIG_GREETING_SETTINGS_LABEL="Messages settings"
COM_HELLOWORLD_CONFIG_GREETING_SETTINGS_DESC="Settings that will be applied to all messages by default"
COM_HELLOWORLD_HELLOWORLD_FIELD_SHOW_CATEGORY_LABEL="Show category"
COM_HELLOWORLD_HELLOWORLD_FIELD_SHOW_CATEGORY_DESC="If set to Show, the title of the message’s category will show."
Installation manifest[edit]
In the installation manifest, we have updated the version number and added config.xml
helloworld.xml
Testing your component[edit]
For details on how to install the component into your Joomla! site, refer to the information provided in Part 01.
File listing[edit]
- helloworld.xml
- site/index.html
- site/helloworld.php
- site/controller.php
- site/views/index.html
- site/views/helloworld/index.html
- site/views/helloworld/view.html.php
- site/views/helloworld/tmpl/index.html
- site/views/helloworld/tmpl/default.php
- site/views/helloworld/tmpl/default.xml
- site/models/index.html
- site/models/helloworld.php
- site/language/index.html
- site/language/en-GB/index.html
- site/language/en-GB/en-GB.com_helloworld.ini
- admin/index.html
- admin/helloworld.php
- admin/controller.php
- admin/config.xml
- admin/helpers/index.html
- admin/helpers/helloworld.php
- admin/controllers/index.html
- admin/controllers/helloworld.php
- admin/controllers/helloworlds.php
- admin/models/index.html
- admin/models/helloworld.php
- admin/models/helloworlds.php
- admin/models/fields/index.html
- admin/models/fields/helloworld.php
- admin/models/forms/index.html
- admin/models/forms/helloworld.xml
- admin/models/rules/index.html
- admin/models/rules/greeting.php
- admin/models/helloworld.php
- admin/views/index.html
- admin/views/helloworld/index.html
- admin/views/helloworld/view.html.php
- admin/views/helloworld/tmpl/index.html
- admin/views/helloworld/tmpl/edit.php
- admin/views/helloworlds/index.html
- admin/views/helloworlds/view.html.php
- admin/views/helloworlds/tmpl/index.html
- admin/views/helloworlds/tmpl/default.php
- admin/views/helloworlds/tmpl/default_head.php
- admin/views/helloworlds/tmpl/default_body.php
- admin/views/helloworlds/tmpl/default_foot.php
- admin/tables/index.html
- admin/tables/helloworld.php
- admin/sql/index.html
- admin/sql/install.mysql.utf8.sql
- admin/sql/uninstall.mysql.utf8.sql
- admin/language/index.html
- admin/language/en-GB/index.html
- admin/language/en-GB/en-GB.com_helloworld.ini
- admin/language/en-GB/en-GB.com_helloworld.sys.ini
- media/index.html
- media/images/index.html
- media/images/tux-16x16.png
- media/images/tux-48x48.png
- media/js/index.html
- media/js/helloworld.js
Download this part[edit]
Articles in this series[edit]
This tutorial is supported by the following versions of Joomla!
- Introduction
- Part 01 - Developing a Basic Component
- Part 02 - Adding a view to the frontend
- Part 03 - Adding a menu item type to the frontend
- Part 04 - Adding a model to the frontend
- Part 05 - Adding options to menu items
- Part 06 - Using a database
- Part 07 - Basic backend
- Part 08 - Adding language translation
- Part 09 - Adding actions to backend
- Part 10 - Adding decorations to the backend
- Part 11 - Adding validation
- Part 12 - Adding categories
- Part 13 - Adding component options
- Part 14 - Adding ACL
- Part 15 - Adding a script file