Skip to content
This repository has been archived by the owner on Nov 28, 2017. It is now read-only.

Updated guide #16

Open
wants to merge 5 commits into
base: step-6-using-the-database
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions admin/models/fields/helloworld.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
<?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;
defined('_JEXEC') or die('Restricted access');

// import the list field type
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');

/**
* HelloWorld Form Field class for the HelloWorld component
*
* @since 0.0.1
*/
class JFormFieldHelloWorld extends JFormFieldList
{
Expand All @@ -21,7 +29,7 @@ class JFormFieldHelloWorld extends JFormFieldList
/**
* Method to get a list of options for a list input.
*
* @return array An array of JHtml options.
* @return array An array of JHtml options.
*/
protected function getOptions()
{
Expand All @@ -32,15 +40,17 @@ protected function getOptions()
$db->setQuery((string) $query);
$messages = $db->loadObjectList();
$options = array();

if ($messages)
{
foreach ($messages as $message)
{
$options[] = JHtml::_('select.option', $message->id, $message->greeting);
}
}

$options = array_merge(parent::getOptions(), $options);

return $options;
}
}
}
20 changes: 12 additions & 8 deletions admin/sql/install.mysql.utf8.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
DROP TABLE IF EXISTS `#__helloworld`;

CREATE TABLE `#__helloworld` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`greeting` varchar(25) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;

`id` INT(11) NOT NULL AUTO_INCREMENT,
`greeting` VARCHAR(25) NOT NULL,
`published` tinyint(4) NOT NULL,
PRIMARY KEY (`id`)
)
ENGINE =MyISAM
AUTO_INCREMENT =0
DEFAULT CHARSET =utf8;

INSERT INTO `#__helloworld` (`greeting`) VALUES
('Hello World!'),
('Good bye World!');
('Hello World!'),
('Good bye World!');
20 changes: 12 additions & 8 deletions admin/sql/updates/mysql/0.0.6.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
DROP TABLE IF EXISTS `#__helloworld`;

CREATE TABLE `#__helloworld` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`greeting` varchar(25) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;

`id` INT(11) NOT NULL AUTO_INCREMENT,
`greeting` VARCHAR(25) NOT NULL,
`published` tinyint(4) NOT NULL,
PRIMARY KEY (`id`)
)
ENGINE =MyISAM
AUTO_INCREMENT =0
DEFAULT CHARSET =utf8;

INSERT INTO `#__helloworld` (`greeting`) VALUES
('Hello World!'),
('Good bye World!');
('Hello World!'),
('Good bye World!');
16 changes: 11 additions & 5 deletions admin/tables/helloworld.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
<?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
defined('_JEXEC') or die('Restricted access');

// import Joomla table library
jimport('joomla.database.table');

/**
* Hello Table class
*
* @since 0.0.1
*/
class HelloWorldTableHelloWorld extends JTable
{
/**
* Constructor
*
* @param object Database connector object
* @param JDatabaseDriver &$db A database connector object
*/
function __construct(&$db)
{
parent::__construct('#__helloworld', 'id', $db);
}
}
}
18 changes: 8 additions & 10 deletions helloworld.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="component"
version="2.5.0"
method="upgrade">
<extension type="component" version="3.2.0" method="upgrade">

<name>Hello World!</name>
<!-- The following elements are optional and free of formatting constraints -->
<creationDate>November 2009</creationDate>
<creationDate>January 2014</creationDate>
<author>John Doe</author>
<authorEmail>[email protected]</authorEmail>
<authorUrl>http://www.example.org</authorUrl>
Expand All @@ -26,16 +24,16 @@
<file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file>
</sql>
</uninstall>
<update> <!-- Runs on update; New in 2.5 -->
<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 -->
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>
Expand All @@ -46,11 +44,11 @@

<administration>
<!-- Administration Menu Section -->
<menu>Hello World!</menu>
<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 -->
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>
Expand Down
15 changes: 11 additions & 4 deletions site/controller.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<?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');

// import Joomla controller library
jimport('joomla.application.component.controller');

/**
* Hello World Component Controller
*
* @since 0.0.1
*/
class HelloWorldController extends JControllerLegacy
{
}
}
13 changes: 9 additions & 4 deletions site/helloworld.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<?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');

// import joomla controller library
jimport('joomla.application.component.controller');

// Get an instance of the controller prefixed by HelloWorld
$controller = JControllerLegacy::getInstance('HelloWorld');

Expand All @@ -13,4 +18,4 @@
$controller->execute($input->getCmd('task'));

// Redirect if set by the controller
$controller->redirect();
$controller->redirect();
37 changes: 24 additions & 13 deletions site/models/helloworld.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,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');

// import Joomla modelitem library
jimport('joomla.application.component.modelitem');

/**
* HelloWorld Model
*
* @since 0.0.1
*/
class HelloWorldModelHelloWorld extends JModelItem
{
Expand All @@ -16,13 +23,15 @@ class HelloWorldModelHelloWorld extends JModelItem
protected $messages;

/**
* Returns a reference to the a Table object, always creating it.
* Method to get a table object, load it if necessary.
*
* @param type The table type to instantiate
* @param string A prefix for the table class name. Optional.
* @param array Configuration array for model. Optional.
* @return JTable A database object
* @since 2.5
* @param string $type The table name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return JTable A JTable object
*
* @since 1.6
*/
public function getTable($type = 'HelloWorld', $prefix = 'HelloWorldTable', $config = array())
{
Expand All @@ -31,8 +40,10 @@ public function getTable($type = 'HelloWorld', $prefix = 'HelloWorldTable', $con

/**
* Get the message
* @param int The corresponding id of the message to be retrieved
* @return string The message to be displayed to the user
*
* @param integer $id Greeting Id
*
* @return string Fetched String from Table for relevant Id
*/
public function getMsg($id = 1)
{
Expand All @@ -43,7 +54,7 @@ public function getMsg($id = 1)

if (!isset($this->messages[$id]))
{
//request the selected id
// Request the selected id
$jinput = JFactory::getApplication()->input;
$id = $jinput->get('id', 1, 'INT');

Expand All @@ -59,4 +70,4 @@ public function getMsg($id = 1)

return $this->messages[$id];
}
}
}
10 changes: 9 additions & 1 deletion site/views/helloworld/tmpl/default.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?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');
?>
<h1><?php echo $this->msg; ?></h1>
<h1><?php echo $this->msg; ?></h1>
24 changes: 19 additions & 5 deletions site/views/helloworld/view.html.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
<?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');

// import Joomla view library
jimport('joomla.application.component.view');

/**
* HTML View class for the HelloWorld Component
*
* @since 0.0.1
*/
class HelloWorldViewHelloWorld extends JViewLegacy
{
// Overwriting JView display method
/**
* 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)
{
// Assign data to the view
Expand All @@ -23,7 +36,8 @@ function display($tpl = null)

return false;
}

// Display the view
parent::display($tpl);
}
}
}