Benutzer:Elkuku/Proyektz/EasyCreator/Creating a package

Aus Joomla! Dokumentation

Wechseln zu: Navigation, Suche

Inhaltsverzeichnis

Description

This is about creating a package with EasyCreator.

A package consists of multiple extensions - e.g. a component and various modules and/or plugins.

Our package will contain four extensions:

  1. Component: Manages your database records - here: your "Hello World's".
  2. Site Module: Displays your records in frontend.
  3. Backend Module: Displays your records in backend.
  4. Content Plugin: Displays your records in content.

StartUp

Using the Benutzer:Elkuku/Proyektz/EasyCreator/Wizard create the following extensions:

1. Component

Type: Package Base
Name: MyTestComponent

2. Module (site)

Type: Hello World 2
Name: MyTestModSite

3. Module (admin)

Type: Backend Plain
Name: MyTestModAdmin

4. Plugin

Type: Content 1
Name: MyTestPlugin

Datei:Wizard start

Set up your package

This step is required to tell EasyCreator how to create your xml installation file and which extensions your package will contain.

  1. Select your project: Component - MyTestComponent.
    go to Building and find the tab named Package.
  2. Click Add Module and select your site module MyTestModSite.
    Under Position type left - the position in your frontend template.
  3. Click Add Module again and select your admin module MyTestModAdmin.
    Under Position type cpanel - the position in your admin template.
  4. Click Add Plugin and select your plugin MyTestPlugin.
  5. Click Save.

Your package setup has finished. Datei:Package setup

We go for the code

We will modify the created modules and the plugin to pull the data from the components table and display it in a HTML table.

Remember - this is for demo purpose only - It's a Hello world package !

2. Module (site)

Datei:folder_blue.png /modules/mod_mytestmodsite
Datei:file_php.png helper.php

public function getItems($userCount)
{
	//--Get a reference to the database
	$db = &JFactory::getDBO();
 
	//--Get a list of all items
	$query = 'SELECT *'
		. ' FROM `#__mytestcomponent`';
 
	$db->setQuery($query);
	$items = ($items = $db->loadAssocList()) ? $items : array();
 
	return $items;
}//function

Datei:folder_blue.png /modules/mod_mytestmodsite/tmpl
Datei:file_php.png default.php

<table width="100%">
	<tr>
		<?php
		foreach (array_keys($items[0]) as $key)
		{
			echo '<td class="sectiontableheader">'.$key.'</th>';
		}//foreach
		?>
	</tr>
	<?php
	$k = 0;
	foreach ($items as $item)
	{
		echo '<tr class="sectiontableentry'.($k + 1).'">';
		foreach ($item as $key=>$value)
		{
			echo '<td>'.$value.'</td>';
		}//foreach
 
		echo '</tr>';
		$k = 1 - $k;
	}//foreach
	?>
</table>

3. Module (admin)

Datei:folder_blue.png /administrator/modules/mod_mytestmodadmin
Datei:file_php.png mod_mytestadmin.php

//--Get a reference to the database
$db =& JFactory::getDBO();
 
//--Get a list of all items
$query = 'SELECT *'
		. ' FROM `#__mytestcomponent`';
 
$db->setQuery($query);
$items = ($items = $db->loadAssocList()) ? $items : array();
?>
 
<table class="adminlist" width="100%">
<thead>
	<tr>
		<?php
		foreach (array_keys($items[0]) as $key)
		{
			echo '<th>'.$key.'</th>';
		}//foreach
		?>
	</tr>
	</thead>
	<?php
	$k = 0;
	foreach ($items as $item)
	{
		echo '<tr class="row'.($k).'">';
		foreach ($item as $key=>$value)
		{
			echo '<td>'.$value.'</td>';
		}//foreach
 
		echo '</tr>';
		$k = 1 - $k;
	}//foreach
	?>
</table>

4. Plugin MyTestPlugin

Datei:folder_blue.png /plugins/content/
Datei:file_php.png mytestplugin.php

function mytestplugin( &$row, &$params, $page=0 )
{
	if( ! strpos($row->text, '{triggerMyTestPlugin'))
	{
		//--The tag is not found in content - abort..
		return;
	}
 
	//--Search for this tag in the content
	$regex = '/{triggerMyTestPlugin\s*.*?}/i';
 
	// get a reference to the database
	$db = &JFactory::getDBO();
 
	// get a list of all users
	$query = 'SELECT *'
			. ' FROM `#__mytestcomponent`';
 
	$db->setQuery($query);
	$items = ($items = $db->loadAssocList()) ? $items : array();
 
	$replacement = '';
 
	$replacement .= '<table width="50%">';
	$replacement .= '    <tr>';
	foreach (array_keys($items[0]) as $key)
	{
		$replacement .= '      <th class"sectiontableheader">'.$key.'</th>';
	}//foreach
	$replacement .= '    </tr>';
	$k = 0;
	foreach ($items as $item)
	{
		$replacement .= '  <tr class="sectiontableentry'.($k+1).'">';
		foreach ($item as $key=>$value)
		{
			$replacement .= '    <td>'.$value.'</td>';
		}//foreach
 
		$replacement .= '  </tr>';
		$k = 1 - $k;
	}//foreach
	$replacement .= '</table>';
 
	//--Replace tag in content
	$row->text = preg_replace( $regex, $replacement, $row->text );
 
	return;
}//function

Screenshots

1) Component 2) Frontend Module 3) Backend Module 4) Content Plugin

Thumbnail Thumbnail Thumbnail Position: 'cpanel' Thumbnail

Create the install package

Select "Package" Make sure to select your desired packing format and click on "Create" Thumbnail

Install your package

Download your package and save it to disk.

Switch over to another Joomla installation and try installing your package Thumbnail

Have fun packing =;) Your Easy-Joomla! Team

Persönliche Werkzeuge
Team Navigation