Difference between revisions of "Developing an MVC Component/Adding categories"
From Joomla! Documentation
< J3.x:Developing an MVC Component
Betweenbrain (talk | contribs) (Created page with "{{:J3.1:Developing a MVC Component}} {{review}} This is a multiple-article series of tutorials on how to develop a Model-View-Contoller Component for Joomla! Version {{J...") |
(Needs to be marked for translation) |
||
(13 intermediate revisions by 3 users not shown) | |||
Line 4: | Line 4: | ||
This is a multiple-article series of tutorials on how to develop a Model-View-Contoller [[Component]] for Joomla! Version {{JVer|{{CurrentSTSVer|minor}}}}. | This is a multiple-article series of tutorials on how to develop a Model-View-Contoller [[Component]] for Joomla! Version {{JVer|{{CurrentSTSVer|minor}}}}. | ||
+ | |||
+ | == Introduction == | ||
+ | This tutorial is part of the [[J3.2:Developing a MVC Component | Developing a MVC Component for Joomla! 3.2]] tutorial. You are encouraged to read the previous parts of the tutorial before reading this. | ||
+ | |||
+ | The Joomla framework has implemented the use of categories for all components. Adding categorized ability to a component is fairly simple. | ||
+ | |||
+ | == Modifying the SQL == | ||
+ | In order to manage categories, we have to change the SQL tables. | ||
+ | |||
+ | With your favorite editor, modify ''admin/sql/install.mysql.utf8.sql'' and put these lines: | ||
+ | |||
+ | <span id="admin/sql/install.mysql.utf8.sql"> | ||
+ | ''admin/sql/install.mysql.utf8.sql'' | ||
+ | <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, | ||
+ | `published` tinyint(4) NOT NULL, | ||
+ | `catid` int(11) NOT NULL DEFAULT '0', | ||
+ | PRIMARY KEY (`id`) | ||
+ | ) | ||
+ | ENGINE =MyISAM | ||
+ | AUTO_INCREMENT =0 | ||
+ | DEFAULT CHARSET =utf8; | ||
+ | |||
+ | INSERT INTO `#__helloworld` (`greeting`) VALUES | ||
+ | ('Hello World!'), | ||
+ | ('Good bye World!'); | ||
+ | |||
+ | </source> | ||
+ | </span> | ||
+ | |||
+ | <span id="admin/sql/updates/mysql/0.0.12.sql"> | ||
+ | ''admin/sql/updates/mysql/0.0.12.sql'' | ||
+ | <source lang="sql"> | ||
+ | ALTER TABLE `#__helloworld` ADD `catid` int(11) NOT NULL DEFAULT '0'; | ||
+ | </source> | ||
+ | </span> | ||
+ | |||
+ | == Modifying the form == | ||
+ | A HelloWorld message can now belong to a category. We have to modify the editing form. In the ''admin/models/forms/helloworld.xml'' file, put these lines: | ||
+ | |||
+ | <span id="admin/models/forms/helloworld.xml"> | ||
+ | ''admin/models/forms/helloworld.xml'' | ||
+ | <source lang="xml" highlight="21-32"> | ||
+ | <?xml version="1.0" encoding="utf-8"?> | ||
+ | <form | ||
+ | addrulepath="/administrator/components/com_helloworld/models/rules" | ||
+ | > | ||
+ | <fieldset> | ||
+ | <field | ||
+ | name="id" | ||
+ | type="hidden" | ||
+ | /> | ||
+ | <field | ||
+ | name="greeting" | ||
+ | type="text" | ||
+ | label="COM_HELLOWORLD_HELLOWORLD_GREETING_LABEL" | ||
+ | description="COM_HELLOWORLD_HELLOWORLD_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> | ||
+ | </form> | ||
+ | </source> | ||
+ | </span> | ||
+ | |||
+ | Note that the category can be 0 (representing no category). | ||
+ | |||
+ | == Modifying the menu type == | ||
+ | The HelloWorld menu type displays a drop down list of all messages. If the message is categorized, we have to add the category in this display. | ||
+ | |||
+ | In the ''admin/models/fields/helloworld.php'' file, put these lines: | ||
+ | |||
+ | <span id="admin/models/fields/helloworld.php"> | ||
+ | ''admin/models/fields/helloworld.php'' | ||
+ | <source lang="php" highlight="38,40-42,51,52"> | ||
+ | <?php | ||
+ | /** | ||
+ | * @package Joomla.Administrator | ||
+ | * @subpackage com_helloworld | ||
+ | * | ||
+ | * @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved. | ||
+ | * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
+ | */ | ||
+ | |||
+ | // No direct access to this file | ||
+ | defined('_JEXEC') or die('Restricted access'); | ||
+ | |||
+ | JFormHelper::loadFieldClass('list'); | ||
+ | |||
+ | /** | ||
+ | * HelloWorld Form Field class for the HelloWorld component | ||
+ | * | ||
+ | * @since 0.0.1 | ||
+ | */ | ||
+ | class JFormFieldHelloWorld extends JFormFieldList | ||
+ | { | ||
+ | /** | ||
+ | * The field type. | ||
+ | * | ||
+ | * @var string | ||
+ | */ | ||
+ | protected $type = 'HelloWorld'; | ||
+ | |||
+ | /** | ||
+ | * Method to get a list of options for a list input. | ||
+ | * | ||
+ | * @return array An array of JHtml options. | ||
+ | */ | ||
+ | protected function getOptions() | ||
+ | { | ||
+ | $db = JFactory::getDBO(); | ||
+ | $query = $db->getQuery(true); | ||
+ | $query->select('#__helloworld.id as id,greeting,#__categories.title as category,catid'); | ||
+ | $query->from('#__helloworld'); | ||
+ | $query->leftJoin('#__categories on catid=#__categories.id'); | ||
+ | // Retrieve only published items | ||
+ | $query->where('#__helloworld.published = 1'); | ||
+ | $db->setQuery((string) $query); | ||
+ | $messages = $db->loadObjectList(); | ||
+ | $options = array(); | ||
+ | |||
+ | if ($messages) | ||
+ | { | ||
+ | foreach ($messages as $message) | ||
+ | { | ||
+ | $options[] = JHtml::_('select.option', $message->id, $message->greeting . | ||
+ | ($message->catid ? ' (' . $message->category . ')' : '')); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | $options = array_merge(parent::getOptions(), $options); | ||
+ | |||
+ | return $options; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </source> | ||
+ | </span> | ||
+ | |||
+ | It will now display the category between parenthesis. | ||
+ | Note: We have added a where clause too to filter out unpublished items. | ||
+ | |||
+ | == Managing the submenu == | ||
+ | The ''com_categories'' component allows to set the submenu using a helper file. With your favorite file manager and editor, put a ''admin/helpers/helloworld.php'' file containing these lines: | ||
+ | |||
+ | <span id="admin/helpers/helloworld.php"> | ||
+ | ''admin/helpers/helloworld.php'' | ||
+ | <source lang="php"> | ||
+ | <?php | ||
+ | /** | ||
+ | * @package Joomla.Administrator | ||
+ | * @subpackage com_helloworld | ||
+ | * | ||
+ | * @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved. | ||
+ | * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
+ | */ | ||
+ | |||
+ | // No direct access to this file | ||
+ | defined('_JEXEC') or die('Restricted access'); | ||
+ | |||
+ | /** | ||
+ | * HelloWorld component helper. | ||
+ | * | ||
+ | * @param string $submenu The name of the active view. | ||
+ | * | ||
+ | * @return void | ||
+ | * | ||
+ | * @since 1.6 | ||
+ | */ | ||
+ | abstract class HelloWorldHelper | ||
+ | { | ||
+ | /** | ||
+ | * Configure the Linkbar. | ||
+ | * | ||
+ | * @return Bool | ||
+ | */ | ||
+ | |||
+ | public static function addSubmenu($submenu) | ||
+ | { | ||
+ | JSubMenuHelper::addEntry( | ||
+ | JText::_('COM_HELLOWORLD_SUBMENU_MESSAGES'), | ||
+ | 'index.php?option=com_helloworld', | ||
+ | $submenu == 'messages' | ||
+ | ); | ||
+ | |||
+ | JSubMenuHelper::addEntry( | ||
+ | JText::_('COM_HELLOWORLD_SUBMENU_CATEGORIES'), | ||
+ | 'index.php?option=com_categories&view=categories&extension=com_helloworld', | ||
+ | $submenu == 'categories' | ||
+ | ); | ||
+ | |||
+ | // Set some global property | ||
+ | $document = JFactory::getDocument(); | ||
+ | $document->addStyleDeclaration('.icon-48-helloworld ' . | ||
+ | '{background-image: url(../media/com_helloworld/images/tux-48x48.png);}'); | ||
+ | if ($submenu == 'categories') | ||
+ | { | ||
+ | $document->setTitle(JText::_('COM_HELLOWORLD_ADMINISTRATION_CATEGORIES')); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </source> | ||
+ | </span> | ||
+ | '''NOTE:''' You MUST use your component name (without com_) for the helper file name, or else your submenus won't show in category view. | ||
+ | |||
+ | To import the helper class, put these lines in the ''admin/helloworld.php'' file: | ||
+ | |||
+ | <span id="admin/helloworld.php"> | ||
+ | ''admin/helloworld.php'' | ||
+ | <source lang="php" highlight="17-19"> | ||
+ | <?php | ||
+ | /** | ||
+ | * @package Joomla.Administrator | ||
+ | * @subpackage com_helloworld | ||
+ | * | ||
+ | * @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved. | ||
+ | * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
+ | */ | ||
+ | |||
+ | // No direct access to this file | ||
+ | defined('_JEXEC') or die('Restricted access'); | ||
+ | |||
+ | // Set some global property | ||
+ | $document = JFactory::getDocument(); | ||
+ | $document->addStyleDeclaration('.icon-helloworld {background-image: url(../media/com_helloworld/images/tux-16x16.png);}'); | ||
+ | |||
+ | // Require helper file | ||
+ | JLoader::register('HelloWorldHelper', JPATH_COMPONENT . '/helpers/helloworld.php'); | ||
+ | |||
+ | // Get an instance of the controller prefixed by HelloWorld | ||
+ | $controller = JControllerLegacy::getInstance('HelloWorld'); | ||
+ | |||
+ | // Perform the Request task | ||
+ | $input = JFactory::getApplication()->input; | ||
+ | $controller->execute($input->getCmd('task')); | ||
+ | |||
+ | // Redirect if set by the controller | ||
+ | $controller->redirect(); | ||
+ | |||
+ | </source> | ||
+ | </span> | ||
+ | |||
+ | This function will be automatically called by the ''com_categories'' component. Note that it will | ||
+ | * change the submenu | ||
+ | * change some css properties (for displaying icons) | ||
+ | * change the browser title if the submenu is ''categories'' | ||
+ | * change the title and add a ''preferences'' button | ||
+ | |||
+ | The ''.icon-48-helloworld'' css class is now set in the ''addSubmenu'' function. | ||
+ | We have now to call this function in the hellowords view: | ||
+ | |||
+ | <span id="admin/views/helloworlds/view.html.php"> | ||
+ | ''admin/views/helloworlds/view.html.php'' | ||
+ | <source lang="php" highlight="50-52"> | ||
+ | <?php | ||
+ | /** | ||
+ | * @package Joomla.Administrator | ||
+ | * @subpackage com_helloworld | ||
+ | * | ||
+ | * @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved. | ||
+ | * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
+ | */ | ||
+ | |||
+ | // No direct access to this file | ||
+ | defined('_JEXEC') or die('Restricted access'); | ||
+ | |||
+ | /** | ||
+ | * HelloWorlds View | ||
+ | * | ||
+ | * @since 0.0.1 | ||
+ | */ | ||
+ | class HelloWorldViewHelloWorlds extends JViewLegacy | ||
+ | { | ||
+ | /** | ||
+ | * Display the Hello World view | ||
+ | * | ||
+ | * @param string $tpl The name of the template file to parse; automatically searches through the template paths. | ||
+ | * | ||
+ | * @return void | ||
+ | */ | ||
+ | |||
+ | function display($tpl = null) | ||
+ | { | ||
+ | |||
+ | // Get application | ||
+ | $app = JFactory::getApplication(); | ||
+ | $context = "helloworld.list.admin.helloworld"; | ||
+ | // Get data from the model | ||
+ | $this->items = $this->get('Items'); | ||
+ | $this->pagination = $this->get('Pagination'); | ||
+ | $this->state = $this->get('State'); | ||
+ | $this->filter_order = $app->getUserStateFromRequest($context.'filter_order', 'filter_order', 'greeting', 'cmd'); | ||
+ | $this->filter_order_Dir = $app->getUserStateFromRequest($context.'filter_order_Dir', 'filter_order_Dir', 'asc', 'cmd'); | ||
+ | $this->filterForm = $this->get('FilterForm'); | ||
+ | $this->activeFilters = $this->get('ActiveFilters'); | ||
+ | |||
+ | // Check for errors. | ||
+ | if (count($errors = $this->get('Errors'))) | ||
+ | { | ||
+ | JError::raiseError(500, implode('<br />', $errors)); | ||
+ | |||
+ | return false; | ||
+ | } | ||
+ | |||
+ | // Set the submenu | ||
+ | HelloWorldHelper::addSubmenu('helloworlds'); | ||
+ | |||
+ | // Set the toolbar and number of found items | ||
+ | $this->addToolBar(); | ||
+ | |||
+ | // Display the template | ||
+ | parent::display($tpl); | ||
+ | |||
+ | // Set the document | ||
+ | $this->setDocument(); | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Add the page title and toolbar. | ||
+ | * | ||
+ | * @return void | ||
+ | * | ||
+ | * @since 1.6 | ||
+ | */ | ||
+ | protected function addToolBar() | ||
+ | { | ||
+ | $title = JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLDS'); | ||
+ | |||
+ | if ($this->pagination->total) | ||
+ | { | ||
+ | $title .= "<span style='font-size: 0.5em; vertical-align: middle;'>(" . $this->pagination->total . ")</span>"; | ||
+ | } | ||
+ | |||
+ | JToolBarHelper::title($title, 'helloworld'); | ||
+ | JToolBarHelper::addNew('helloworld.add'); | ||
+ | JToolBarHelper::editList('helloworld.edit'); | ||
+ | JToolBarHelper::deleteList('', 'helloworlds.delete'); | ||
+ | } | ||
+ | /** | ||
+ | * Method to set up the document properties | ||
+ | * | ||
+ | * @return void | ||
+ | */ | ||
+ | protected function setDocument() | ||
+ | { | ||
+ | $document = JFactory::getDocument(); | ||
+ | $document->setTitle(JText::_('COM_HELLOWORLD_ADMINISTRATION')); | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | </span> | ||
+ | |||
+ | == Adding some ACL == | ||
+ | <span id="admin/access.xml"> | ||
+ | ''admin/access.xml'' | ||
+ | <source lang="xml"> | ||
+ | <?xml version="1.0" encoding="utf-8" ?> | ||
+ | <access component="com_helloworld"> | ||
+ | <section name="component"> | ||
+ | <action name="core.admin" title="JACTION_ADMIN" description="JACTION_ADMIN_COMPONENT_DESC" /> | ||
+ | <action name="core.manage" title="JACTION_MANAGE" description="JACTION_MANAGE_COMPONENT_DESC" /> | ||
+ | <action name="core.create" title="JACTION_CREATE" description="JACTION_CREATE_COMPONENT_DESC" /> | ||
+ | <action name="core.delete" title="JACTION_DELETE" description="JACTION_DELETE_COMPONENT_DESC" /> | ||
+ | <action name="core.edit" title="JACTION_EDIT" description="JACTION_EDIT_COMPONENT_DESC" /> | ||
+ | </section> | ||
+ | <section name="message"> | ||
+ | <action name="core.delete" title="JACTION_DELETE" description="COM_HELLOWORLD_ACCESS_DELETE_DESC" /> | ||
+ | <action name="core.edit" title="JACTION_EDIT" description="COM_HELLOWORLD_ACCESS_EDIT_DESC" /> | ||
+ | </section> | ||
+ | </access> | ||
+ | </source> | ||
+ | </span> | ||
+ | |||
+ | '''NOTE:''' If you don't add this file, buttons "New" "Edit" and ... don't show in category view . for more information read section Adding ACL on top of the page. | ||
+ | |||
+ | == Adding some translation strings == | ||
+ | Some strings have to be translated. In the ''admin/language/en-GB/en-GB.com_helloworld.ini'' file, put these lines: | ||
+ | |||
+ | <span id="admin/language/en-GB/en-GB.com_helloworld.ini"> | ||
+ | ''admin/language/en-GB/en-GB.com_helloworld.ini'' | ||
+ | <source lang="ini" highlight="7,17-19,34,35"> | ||
+ | ; Joomla! Project | ||
+ | ; Copyright (C) 2005 - 2015 Open Source Matters. All rights reserved. | ||
+ | ; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php | ||
+ | ; Note : All ini files need to be saved as UTF-8 | ||
+ | |||
+ | COM_HELLOWORLD_ADMINISTRATION="HelloWorld - Administration" | ||
+ | COM_HELLOWORLD_ADMINISTRATION_CATEGORIES="HelloWorld - Categories" | ||
+ | COM_HELLOWORLD_NUM="#" | ||
+ | COM_HELLOWORLD_HELLOWORLDS_FILTER="Filters" | ||
+ | COM_HELLOWORLD_PUBLISHED="Published" | ||
+ | COM_HELLOWORLD_HELLOWORLDS_NAME="Name" | ||
+ | COM_HELLOWORLD_ID="Id" | ||
+ | |||
+ | COM_HELLOWORLD_HELLOWORLD_CREATING="HelloWorld - Creating" | ||
+ | COM_HELLOWORLD_HELLOWORLD_DETAILS="Details" | ||
+ | COM_HELLOWORLD_HELLOWORLD_EDITING="HelloWorld - Editing" | ||
+ | COM_HELLOWORLD_HELLOWORLD_ERROR_UNACCEPTABLE="Some values are unacceptable" | ||
+ | COM_HELLOWORLD_HELLOWORLD_FIELD_CATID_DESC="The category the messages belongs to" | ||
+ | COM_HELLOWORLD_HELLOWORLD_FIELD_CATID_LABEL="Category" | ||
+ | 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_MANAGER_HELLOWORLD_EDIT="HelloWorld manager: Edit Message" | ||
+ | COM_HELLOWORLD_MANAGER_HELLOWORLD_NEW="HelloWorld manager: New Message" | ||
+ | COM_HELLOWORLD_MANAGER_HELLOWORLDS="HelloWorld manager" | ||
+ | COM_HELLOWORLD_EDIT_HELLOWORLD="Edit message" | ||
+ | COM_HELLOWORLD_N_ITEMS_DELETED_1="One message deleted" | ||
+ | COM_HELLOWORLD_N_ITEMS_DELETED_MORE="%d messages deleted" | ||
+ | COM_HELLOWORLD_N_ITEMS_PUBLISHED="%d message(s) published" | ||
+ | COM_HELLOWORLD_N_ITEMS_UNPUBLISHED="%d message(s) unpublished" | ||
+ | COM_HELLOWORLD_HELLOWORLD_GREETING_LABEL="Greeting" | ||
+ | COM_HELLOWORLD_HELLOWORLD_GREETING_DESC="Add Hello World Greeting" | ||
+ | COM_HELLOWORLD_SUBMENU_MESSAGES="Messages" | ||
+ | COM_HELLOWORLD_SUBMENU_CATEGORIES="Categories" | ||
+ | |||
+ | </source> | ||
+ | </span> | ||
+ | |||
+ | == Packaging the component == | ||
+ | |||
+ | Content of your code directory | ||
+ | * ''[[#helloworld.xml|helloworld.xml]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Adding_a_view_to_the_site_part#site/helloworld.php|site/helloworld.php]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Adding_a_view_to_the_site_part#site/controller.php|site/controller.php]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/views/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/views/helloworld/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Adding_a_view_to_the_site_part#site/views/helloworld/view.html.php|site/views/helloworld/view.html.php]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/views/helloworld/tmpl/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Using_the_database#site/views/helloworld/tmpl/default.xml|site/views/helloworld/tmpl/default.xml]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Adding_a_view_to_the_site_part#site/views/helloworld/tmpl/default.php|site/views/helloworld/tmpl/default.php]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/models/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Using_the_database#site/models/helloworld.php|site/models/helloworld.php]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/language/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/language/en-GB/index.html]]'' | ||
+ | * [[J3.x:Developing a MVC Component/Adding language management#site.2Flanguage.2Fen-GB.2Fen-GB.com_helloworld.ini|site/language/en-GB/en-GB.com_helloworld.ini]] | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/helloworld.php|admin/helloworld.php]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/controller.php|admin/controller.php]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Adding_categories#admin/access.xml|admin/access.xml]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Adding_categories#admin/helpers/helloworld.php|admin/helpers/helloworld.php]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/helpers/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Using_the_database#admin/sql/install.mysql.utf8.sql|admin/sql/install.mysql.utf8.sql]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Using_the_database#admin/sql/uninstall.mysql.utf8.sql|admin/sql/uninstall.mysql.utf8.sql]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/updates/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/updates/mysql/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#admin/sql/updates/mysql/0.0.1.sql|admin/sql/updates/mysql/0.0.1.sql]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Using_the_database#admin/sql/install.mysql.utf8.sql|admin/sql/updates/mysql/0.0.6.sql]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Adding_categories#admin/sql/updates/mysql/0.0.12.sql|admin/sql/updates/mysql/0.0.12.sql]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/fields/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Using_the_database#admin/models/fields/helloworld.php|admin/models/fields/helloworld.php]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/models/helloworlds.php|admin/models/helloworlds.php]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/models/helloworlds.php|admin/models/helloworld.php]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/forms/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Adding_verifications#admin/models/forms/helloworld.js|admin/models/forms/helloworld.js]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/models/forms/helloworld.xml|admin/models/forms/helloworld.xml]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Adding_verifications#admin/models/rules/greeting.php|admin/models/rules/greeting.php]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/rules/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/controllers/helloworld.php|admin/controllers/helloworld.php]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/controllers/helloworlds.php|admin/controllers/helloworlds.php]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/controllers/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworld/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/views/helloworld/view.html.php|admin/views/helloworld/view.html.php]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/views/helloworld/tmpl/edit.php|admin/views/helloworld/tmpl/edit.php]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Adding_verifications#admin/views/helloworld/submitbutton.js|admin/views/helloworld/submitbutton.js]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworlds/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/views/helloworlds/view.html.php|admin/views/helloworlds/view.html.php]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworlds/tmpl/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/views/helloworlds/tmpl/default.php|admin/views/helloworlds/tmpl/default.php]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/tables/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Using_the_database#admin/tables/helloworld.php|admin/tables/helloworld.php]]'' | ||
+ | * ''[[#admin/language/index.html|admin/language/index.html]]'' | ||
+ | * ''[[#admin/language/en-GB/index.html|admin/language/en-GB/index.html]]'' | ||
+ | * ''[[J3.x:Developing a MVC Component/Adding language management#admin.2Flanguage.2Fen-GB.2Fen-GB.com_helloworld.ini|admin/language/en-GB/en-GB.com_helloworld.ini]]'' | ||
+ | * ''[[J3.x:Developing a MVC Component/Adding language management#admin.2Flanguage.2Fen-GB.2Fen-GB.com_helloworld.sys.ini|admin/language/en-GB/en-GB.com_helloworld.sys.ini]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|media/index.html]]'' | ||
+ | * ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|media/images/index.html]]'' | ||
+ | * ''[[J3.x:Developing_a_MVC_Component/Adding_decorations_to_the_backend#Adding_some_icons|media/images/tux-16x16.png]]'' | ||
+ | * ''[[J3.x:Developing_a_MVC_Component/Adding_decorations_to_the_backend#Adding_some_icons|media/images/tux-48x48.png]]'' | ||
+ | |||
+ | Create a compressed file of this directory or directly download the [https://github.com/scionescire/Joomla-3.2-Hello-World-Component/archive/step-12-adding-categories.zip archive] and install it using the extension manager of Joomla. You can add a menu item of this component using the menu manager in the backend. | ||
+ | |||
+ | <span id="helloworld.xml"> | ||
+ | ''helloworld.xml'' | ||
+ | <source lang="xml" highlight="13,66,77,78"> | ||
+ | <?xml version="1.0" encoding="utf-8"?> | ||
+ | <extension type="component" version="3.2.0" method="upgrade"> | ||
+ | |||
+ | <name>COM_HELLOWORLD</name> | ||
+ | <!-- The following elements are optional and free of formatting constraints --> | ||
+ | <creationDate>February 2015</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.12</version> | ||
+ | <!-- The description is optional and defaults to the name --> | ||
+ | <description>COM_HELLOWORLD_DESCRIPTION</description> | ||
+ | |||
+ | <install> <!-- Runs on install --> | ||
+ | <sql> | ||
+ | <file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file> | ||
+ | </sql> | ||
+ | </install> | ||
+ | <uninstall> <!-- Runs on uninstall --> | ||
+ | <sql> | ||
+ | <file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file> | ||
+ | </sql> | ||
+ | </uninstall> | ||
+ | <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> | ||
+ | <filename>controller.php</filename> | ||
+ | <folder>views</folder> | ||
+ | <folder>models</folder> | ||
+ | </files> | ||
+ | |||
+ | <languages folder="site/language"> | ||
+ | <language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language> | ||
+ | </languages> | ||
+ | |||
+ | <media destination="com_helloworld" folder="media"> | ||
+ | <filename>index.html</filename> | ||
+ | <folder>images</folder> | ||
+ | </media> | ||
+ | |||
+ | <administration> | ||
+ | <!-- Administration Menu Section --> | ||
+ | <menu link='index.php?option=com_helloworld' img="../media/com_helloworld/images/tux-16x16.png">COM_HELLOWORLD_MENU</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> | ||
+ | <filename>controller.php</filename> | ||
+ | <filename>access.xml</filename> | ||
+ | <!-- SQL files section --> | ||
+ | <folder>sql</folder> | ||
+ | <!-- tables files section --> | ||
+ | <folder>tables</folder> | ||
+ | <!-- models files section --> | ||
+ | <folder>models</folder> | ||
+ | <!-- views files section --> | ||
+ | <folder>views</folder> | ||
+ | <!-- controllers files section --> | ||
+ | <folder>controllers</folder> | ||
+ | <!-- helpers files section --> | ||
+ | <folder>helpers</folder> | ||
+ | </files> | ||
+ | <languages folder="admin/language"> | ||
+ | <language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language> | ||
+ | <language tag="en-GB">en-GB/en-GB.com_helloworld.sys.ini</language> | ||
+ | </languages> | ||
+ | </administration> | ||
+ | |||
+ | </extension> | ||
+ | </source> | ||
+ | </span> | ||
+ | {{:J3.2:Developing a MVC Component/Navigate | ||
+ | |prev=Adding verifications <!-- previous article subpage name --> | ||
+ | |||
+ | |next=Adding configuration <!-- next article subpage name -->}} | ||
+ | |||
+ | == Contributors == | ||
+ | *[[User:cdemko|Christophe Demko]] | ||
+ | *[[User:oaksu|Ozgur Aksu]] | ||
+ | *[[User:Anibal.sanchez|Anibal Sanchez]] // Just a fix | ||
+ | *[[User:Postema|Hans Postema]] // Just another fix | ||
+ | *[[User:Scionescire|Scionescire]] | ||
+ | *[[User:Veronika|Veronika Patel]] | ||
+ | |||
[[Category:Joomla! 3.0]] | [[Category:Joomla! 3.0]] | ||
Line 10: | Line 621: | ||
[[Category:Beginner Development]] | [[Category:Beginner Development]] | ||
[[Category:Component Development]] | [[Category:Component Development]] | ||
+ | [Category:Needs image updating/fr|Needs image updating]] |
Revision as of 19:24, 24 March 2015
{{Chunk:Developing a Model-View-Controller (MVC) Component for Joomla!3.1 - Contents/<translate> en</translate>}} <translate> This is a multiple-article series of tutorials on how to develop a Model-View-Controller Component for Joomla! Version.</translate>
<translate> 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).</translate>
This page is tagged because it NEEDS REVIEW. You can help the Joomla! Documentation Wiki by contributing to it.
More pages that need help similar to this one are here. NOTE-If you feel the need is satistified, please remove this notice.
This is a multiple-article series of tutorials on how to develop a Model-View-Contoller Component for Joomla! Version .
Introduction[edit]
This tutorial is part of the Developing a MVC Component for Joomla! 3.2 tutorial. You are encouraged to read the previous parts of the tutorial before reading this.
The Joomla framework has implemented the use of categories for all components. Adding categorized ability to a component is fairly simple.
Modifying the SQL[edit]
In order to manage categories, we have to change the SQL tables.
With your favorite editor, modify admin/sql/install.mysql.utf8.sql and put these lines:
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,
`published` tinyint(4) NOT NULL,
`catid` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
)
ENGINE =MyISAM
AUTO_INCREMENT =0
DEFAULT CHARSET =utf8;
INSERT INTO `#__helloworld` (`greeting`) VALUES
('Hello World!'),
('Good bye World!');
admin/sql/updates/mysql/0.0.12.sql
ALTER TABLE `#__helloworld` ADD `catid` int(11) NOT NULL DEFAULT '0';
Modifying the form[edit]
A HelloWorld message can now belong to a category. We have to modify the editing form. In the admin/models/forms/helloworld.xml file, put these lines:
admin/models/forms/helloworld.xml
<?xml version="1.0" encoding="utf-8"?>
<form
addrulepath="/administrator/components/com_helloworld/models/rules"
>
<fieldset>
<field
name="id"
type="hidden"
/>
<field
name="greeting"
type="text"
label="COM_HELLOWORLD_HELLOWORLD_GREETING_LABEL"
description="COM_HELLOWORLD_HELLOWORLD_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>
</form>
Note that the category can be 0 (representing no category).
[edit]
The HelloWorld menu type displays a drop down list of all messages. If the message is categorized, we have to add the category in this display.
In the admin/models/fields/helloworld.php file, put these lines:
admin/models/fields/helloworld.php
<?php
/**
* @package Joomla.Administrator
* @subpackage com_helloworld
*
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
JFormHelper::loadFieldClass('list');
/**
* HelloWorld Form Field class for the HelloWorld component
*
* @since 0.0.1
*/
class JFormFieldHelloWorld extends JFormFieldList
{
/**
* The field type.
*
* @var string
*/
protected $type = 'HelloWorld';
/**
* Method to get a list of options for a list input.
*
* @return array An array of JHtml options.
*/
protected function getOptions()
{
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('#__helloworld.id as id,greeting,#__categories.title as category,catid');
$query->from('#__helloworld');
$query->leftJoin('#__categories on catid=#__categories.id');
// Retrieve only published items
$query->where('#__helloworld.published = 1');
$db->setQuery((string) $query);
$messages = $db->loadObjectList();
$options = array();
if ($messages)
{
foreach ($messages as $message)
{
$options[] = JHtml::_('select.option', $message->id, $message->greeting .
($message->catid ? ' (' . $message->category . ')' : ''));
}
}
$options = array_merge(parent::getOptions(), $options);
return $options;
}
}
It will now display the category between parenthesis. Note: We have added a where clause too to filter out unpublished items.
[edit]
The com_categories component allows to set the submenu using a helper file. With your favorite file manager and editor, put a admin/helpers/helloworld.php file containing these lines:
admin/helpers/helloworld.php
<?php
/**
* @package Joomla.Administrator
* @subpackage com_helloworld
*
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
/**
* HelloWorld component helper.
*
* @param string $submenu The name of the active view.
*
* @return void
*
* @since 1.6
*/
abstract class HelloWorldHelper
{
/**
* Configure the Linkbar.
*
* @return Bool
*/
public static function addSubmenu($submenu)
{
JSubMenuHelper::addEntry(
JText::_('COM_HELLOWORLD_SUBMENU_MESSAGES'),
'index.php?option=com_helloworld',
$submenu == 'messages'
);
JSubMenuHelper::addEntry(
JText::_('COM_HELLOWORLD_SUBMENU_CATEGORIES'),
'index.php?option=com_categories&view=categories&extension=com_helloworld',
$submenu == 'categories'
);
// Set some global property
$document = JFactory::getDocument();
$document->addStyleDeclaration('.icon-48-helloworld ' .
'{background-image: url(../media/com_helloworld/images/tux-48x48.png);}');
if ($submenu == 'categories')
{
$document->setTitle(JText::_('COM_HELLOWORLD_ADMINISTRATION_CATEGORIES'));
}
}
}
NOTE: You MUST use your component name (without com_) for the helper file name, or else your submenus won't show in category view.
To import the helper class, put these lines in the admin/helloworld.php file:
admin/helloworld.php
<?php
/**
* @package Joomla.Administrator
* @subpackage com_helloworld
*
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// Set some global property
$document = JFactory::getDocument();
$document->addStyleDeclaration('.icon-helloworld {background-image: url(../media/com_helloworld/images/tux-16x16.png);}');
// Require helper file
JLoader::register('HelloWorldHelper', JPATH_COMPONENT . '/helpers/helloworld.php');
// Get an instance of the controller prefixed by HelloWorld
$controller = JControllerLegacy::getInstance('HelloWorld');
// Perform the Request task
$input = JFactory::getApplication()->input;
$controller->execute($input->getCmd('task'));
// Redirect if set by the controller
$controller->redirect();
This function will be automatically called by the com_categories component. Note that it will
- change the submenu
- change some css properties (for displaying icons)
- change the browser title if the submenu is categories
- change the title and add a preferences button
The .icon-48-helloworld css class is now set in the addSubmenu function. We have now to call this function in the hellowords view:
admin/views/helloworlds/view.html.php
<?php
/**
* @package Joomla.Administrator
* @subpackage com_helloworld
*
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
/**
* HelloWorlds View
*
* @since 0.0.1
*/
class HelloWorldViewHelloWorlds extends JViewLegacy
{
/**
* Display the Hello World view
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*/
function display($tpl = null)
{
// Get application
$app = JFactory::getApplication();
$context = "helloworld.list.admin.helloworld";
// Get data from the model
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->state = $this->get('State');
$this->filter_order = $app->getUserStateFromRequest($context.'filter_order', 'filter_order', 'greeting', 'cmd');
$this->filter_order_Dir = $app->getUserStateFromRequest($context.'filter_order_Dir', 'filter_order_Dir', 'asc', 'cmd');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
// Check for errors.
if (count($errors = $this->get('Errors')))
{
JError::raiseError(500, implode('<br />', $errors));
return false;
}
// Set the submenu
HelloWorldHelper::addSubmenu('helloworlds');
// Set the toolbar and number of found items
$this->addToolBar();
// Display the template
parent::display($tpl);
// Set the document
$this->setDocument();
}
/**
* Add the page title and toolbar.
*
* @return void
*
* @since 1.6
*/
protected function addToolBar()
{
$title = JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLDS');
if ($this->pagination->total)
{
$title .= "<span style='font-size: 0.5em; vertical-align: middle;'>(" . $this->pagination->total . ")</span>";
}
JToolBarHelper::title($title, 'helloworld');
JToolBarHelper::addNew('helloworld.add');
JToolBarHelper::editList('helloworld.edit');
JToolBarHelper::deleteList('', 'helloworlds.delete');
}
/**
* Method to set up the document properties
*
* @return void
*/
protected function setDocument()
{
$document = JFactory::getDocument();
$document->setTitle(JText::_('COM_HELLOWORLD_ADMINISTRATION'));
}
}
Adding some ACL[edit]
admin/access.xml
<?xml version="1.0" encoding="utf-8" ?>
<access component="com_helloworld">
<section name="component">
<action name="core.admin" title="JACTION_ADMIN" description="JACTION_ADMIN_COMPONENT_DESC" />
<action name="core.manage" title="JACTION_MANAGE" description="JACTION_MANAGE_COMPONENT_DESC" />
<action name="core.create" title="JACTION_CREATE" description="JACTION_CREATE_COMPONENT_DESC" />
<action name="core.delete" title="JACTION_DELETE" description="JACTION_DELETE_COMPONENT_DESC" />
<action name="core.edit" title="JACTION_EDIT" description="JACTION_EDIT_COMPONENT_DESC" />
</section>
<section name="message">
<action name="core.delete" title="JACTION_DELETE" description="COM_HELLOWORLD_ACCESS_DELETE_DESC" />
<action name="core.edit" title="JACTION_EDIT" description="COM_HELLOWORLD_ACCESS_EDIT_DESC" />
</section>
</access>
NOTE: If you don't add this file, buttons "New" "Edit" and ... don't show in category view . for more information read section Adding ACL on top of the page.
Adding some translation strings[edit]
Some strings have to be translated. In the admin/language/en-GB/en-GB.com_helloworld.ini file, put these lines:
admin/language/en-GB/en-GB.com_helloworld.ini
; Joomla! Project
; Copyright (C) 2005 - 2015 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8
COM_HELLOWORLD_ADMINISTRATION="HelloWorld - Administration"
COM_HELLOWORLD_ADMINISTRATION_CATEGORIES="HelloWorld - Categories"
COM_HELLOWORLD_NUM="#"
COM_HELLOWORLD_HELLOWORLDS_FILTER="Filters"
COM_HELLOWORLD_PUBLISHED="Published"
COM_HELLOWORLD_HELLOWORLDS_NAME="Name"
COM_HELLOWORLD_ID="Id"
COM_HELLOWORLD_HELLOWORLD_CREATING="HelloWorld - Creating"
COM_HELLOWORLD_HELLOWORLD_DETAILS="Details"
COM_HELLOWORLD_HELLOWORLD_EDITING="HelloWorld - Editing"
COM_HELLOWORLD_HELLOWORLD_ERROR_UNACCEPTABLE="Some values are unacceptable"
COM_HELLOWORLD_HELLOWORLD_FIELD_CATID_DESC="The category the messages belongs to"
COM_HELLOWORLD_HELLOWORLD_FIELD_CATID_LABEL="Category"
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_MANAGER_HELLOWORLD_EDIT="HelloWorld manager: Edit Message"
COM_HELLOWORLD_MANAGER_HELLOWORLD_NEW="HelloWorld manager: New Message"
COM_HELLOWORLD_MANAGER_HELLOWORLDS="HelloWorld manager"
COM_HELLOWORLD_EDIT_HELLOWORLD="Edit message"
COM_HELLOWORLD_N_ITEMS_DELETED_1="One message deleted"
COM_HELLOWORLD_N_ITEMS_DELETED_MORE="%d messages deleted"
COM_HELLOWORLD_N_ITEMS_PUBLISHED="%d message(s) published"
COM_HELLOWORLD_N_ITEMS_UNPUBLISHED="%d message(s) unpublished"
COM_HELLOWORLD_HELLOWORLD_GREETING_LABEL="Greeting"
COM_HELLOWORLD_HELLOWORLD_GREETING_DESC="Add Hello World Greeting"
COM_HELLOWORLD_SUBMENU_MESSAGES="Messages"
COM_HELLOWORLD_SUBMENU_CATEGORIES="Categories"
Packaging the component[edit]
Content of your code directory
- helloworld.xml
- site/helloworld.php
- site/index.html
- 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.xml
- site/views/helloworld/tmpl/default.php
- 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/access.xml
- admin/helpers/helloworld.php
- admin/helpers/index.html
- admin/sql/index.html
- admin/sql/install.mysql.utf8.sql
- admin/sql/uninstall.mysql.utf8.sql
- admin/sql/updates/index.html
- admin/sql/updates/mysql/index.html
- admin/sql/updates/mysql/0.0.1.sql
- admin/sql/updates/mysql/0.0.6.sql
- admin/sql/updates/mysql/0.0.12.sql
- admin/models/index.html
- admin/models/fields/index.html
- admin/models/fields/helloworld.php
- admin/models/helloworlds.php
- admin/models/helloworld.php
- admin/models/forms/index.html
- admin/models/forms/helloworld.js
- admin/models/forms/helloworld.xml
- admin/models/rules/greeting.php
- admin/models/rules/index.html
- admin/controllers/helloworld.php
- admin/controllers/helloworlds.php
- admin/controllers/index.html
- admin/views/index.html
- admin/views/helloworld/index.html
- admin/views/helloworld/view.html.php
- admin/views/helloworld/tmpl/edit.php
- admin/views/helloworld/submitbutton.js
- admin/views/helloworlds/index.html
- admin/views/helloworlds/view.html.php
- admin/views/helloworlds/tmpl/index.html
- admin/views/helloworlds/tmpl/default.php
- admin/tables/index.html
- admin/tables/helloworld.php
- 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
Create a compressed file of this directory or directly download the archive and install it using the extension manager of Joomla. You can add a menu item of this component using the menu manager in the backend.
helloworld.xml
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.2.0" method="upgrade">
<name>COM_HELLOWORLD</name>
<!-- The following elements are optional and free of formatting constraints -->
<creationDate>February 2015</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.12</version>
<!-- The description is optional and defaults to the name -->
<description>COM_HELLOWORLD_DESCRIPTION</description>
<install> <!-- Runs on install -->
<sql>
<file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file>
</sql>
</install>
<uninstall> <!-- Runs on uninstall -->
<sql>
<file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file>
</sql>
</uninstall>
<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>
<filename>controller.php</filename>
<folder>views</folder>
<folder>models</folder>
</files>
<languages folder="site/language">
<language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
</languages>
<media destination="com_helloworld" folder="media">
<filename>index.html</filename>
<folder>images</folder>
</media>
<administration>
<!-- Administration Menu Section -->
<menu link='index.php?option=com_helloworld' img="../media/com_helloworld/images/tux-16x16.png">COM_HELLOWORLD_MENU</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>
<filename>controller.php</filename>
<filename>access.xml</filename>
<!-- SQL files section -->
<folder>sql</folder>
<!-- tables files section -->
<folder>tables</folder>
<!-- models files section -->
<folder>models</folder>
<!-- views files section -->
<folder>views</folder>
<!-- controllers files section -->
<folder>controllers</folder>
<!-- helpers files section -->
<folder>helpers</folder>
</files>
<languages folder="admin/language">
<language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
<language tag="en-GB">en-GB/en-GB.com_helloworld.sys.ini</language>
</languages>
</administration>
</extension>
J3.x:Developing a MVC Component/Navigate
Contributors[edit]
- Christophe Demko
- Ozgur Aksu
- Anibal Sanchez // Just a fix
- Hans Postema // Just another fix
- Scionescire
- Veronika Patel
[Category:Needs image updating/fr|Needs image updating]]