for frontend example see "Source"
frontend = 1 line of code :) ( if you don't count the "check for Koowa" and the templates)
For example with 3 tables checkout com_bib in "source"
The Joomla! example is taken from the hello world tutorial at http://docs.joomla.org/Developers
The Nooku Framework example is written for Nooku Framework v0.7, based on revision 1114.
It's not 100% the same, bit it gives an idea.
Joomla! Framework Joomla! Framework + Nooku Frameworkinstall.sqlinstall.sqlCREATE TABLE `#__hello` (
`id` int(11) NOT NULL auto_increment,
`greeting` varchar(25) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
see: NameConventionTablesCREATE TABLE `#__hello_greetings` (
`hello_greeting_id` SERIAL,
`greeting` varchar(25) NOT NULL
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
administrator/components/com_hello/hello.phpadministrator/components/com_hello/hello.php// Require the base controller
require_once( JPATH_COMPONENT.DS.'controller.php' );
// Require specific controller if requested
if($controller = JRequest::getWord('controller')) {
$path = JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php';
if (file_exists($path)) {
require_once $path;
} else {
$controller = '';
}
}
// Create the controller
$classname = 'HellosController'.$controller;
$controller = new $classname( );
// Perform the Request task
$controller->execute( JRequest::getVar( 'task' ) );
// Redirect if set by the controller
$controller->redirect();
see: Entrypoint
// Check if Nooku Framework (codename=Koowa) is active
if(!defined('KOOWA')) {
JError::raiseWarning(0, JText::_("Koowa wasn't found. Please install the Koowa plugin and enable it."));
return;
}
// Create the component dispatcher
KFactory::get('admin::com.hello.dispatcher', array('default_view' => 'greetings'))
->dispatch();
administrator/components/com_hello/controller.phpController automatically created by Nooku Framework
jimport('joomla.application.component.controller');
class HellosController extends JController
{
/**
* Method to display the view
*
* @access public
*/
function display()
{
parent::display();
}
}
administrator/components/com_hello/controllers/hello.phpadministrator/components/com_hello/tables/hello.phpadministrator/components/com_hello/controllers/greeting.phpclass HellosControllerHello extends HellosController
{
/**
* constructor (registers additional tasks to methods)
* @return void
*/
function __construct()
{
parent::__construct();
// Register Extra tasks
$this->registerTask( 'add' , 'edit' );
}
/**
* display the edit form
* @return void
*/
function edit()
{
JRequest::setVar( 'view', 'hello' );
JRequest::setVar( 'layout', 'form' );
JRequest::setVar('hidemainmenu', 1);
parent::display();
}
/**
* save a record (and redirect to main page)
* @return void
*/
function save()
{
$model = $this->getModel('hello');
if ($model->store($post)) {
$msg = JText::_( 'Greeting Saved!' );
} else {
$msg = JText::_( 'Error Saving Greeting' );
}
// Check the table in so it can be edited.... we are done with it anyway
$link = 'index.php?option=com_hello';
$this->setRedirect($link, $msg);
}
/**
* remove record(s)
* @return void
*/
function remove()
{
$model = $this->getModel('hello');
if(!$model->delete()) {
$msg = JText::_( 'Error: One or More Greetings Could not be Deleted' );
} else {
$msg = JText::_( 'Greeting(s) Deleted' );
}
$this->setRedirect( 'index.php?option=com_hello', $msg );
}
/**
* cancel editing a record
* @return void
*/
function cancel()
{
$msg = JText::_( 'Operation Cancelled' );
$this->setRedirect( 'index.php?option=com_hello', $msg );
}
}
<?php
// we want to use the form controller instead of the default controller, so we add the class
class HelloControllerGreeting extends KControllerForm
{
}
class TableHello extends JTable
{
/**
* Primary Key
*
* @var int
*/
var $id = null;
/**
* @var string
*/
var $greeting = null;
/**
* Constructor
*
* @param object Database connector object
*/
function TableHello(& $db) {
parent::__construct('#__hello', 'id', $db);
}
}
Table automatically created by Nooku Frameworkadministrator/components/com_hello/models/hello.php
jimport('joomla.application.component.model');
class HellosModelHello extends JModel
{
/**
* Constructor that retrieves the ID from the request
*
* @access public
* @return void
*/
function __construct()
{
parent::__construct();
$array = JRequest::getVar('cid', 0, '', 'array');
$this->setId((int)$array[0]);
}
/**
* Method to set the hello identifier
*
* @access public
* @param int Hello identifier
* @return void
*/
function setId($id)
{
// Set id and wipe data
$this->_id = $id;
$this->_data = null;
}
/**
* Method to get a hello
* @return object with data
*/
function &getData()
{
// Load the data
if (empty( $this->_data )) {
$query = ' SELECT * FROM #__hello '.
' WHERE id = '.$this->_id;
$this->_db->setQuery( $query );
$this->_data = $this->_db->loadObject();
}
if (!$this->_data) {
$this->_data = new stdClass();
$this->_data->id = 0;
$this->_data->greeting = null;
}
return $this->_data;
}
/**
* Method to store a record
*
* @access public
* @return boolean True on success
*/
function store()
{
$row =& $this->getTable();
$data = JRequest::get( 'post' );
// Bind the form fields to the hello table
if (!$row->bind($data)) {
$this->setError($this->_db->getErrorMsg());
return false;
}
// Make sure the hello record is valid
if (!$row->check()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
// Store the web link table to the database
if (!$row->store()) {
$this->setError( $row->getErrorMsg() );
return false;
}
return true;
}
/**
* Method to delete record(s)
*
* @access public
* @return boolean True on success
*/
function delete()
{
$cids = JRequest::getVar( 'cid', array(0), 'post', 'array' );
$row =& $this->getTable();
if (count( $cids )) {
foreach($cids as $cid) {
if (!$row->delete( $cid )) {
$this->setError( $row->getErrorMsg() );
return false;
}
}
}
return true;
}
}
Model automatically created by Nooku Frameworkadministrator/components/com_hello/models/hellos.php
jimport( 'joomla.application.component.model' );
class HellosModelHellos extends JModel
{
/**
* Hellos data array
*
* @var array
*/
var $_data;
/**
* Returns the query
* @return string The query to be used to retrieve the rows from the database
*/
function _buildQuery()
{
$query = ' SELECT * FROM #__hello ';
return $query;
}
/**
* Retrieves the hello data
* @return array Array of objects containing the data from the database
*/
function getData()
{
// Lets load the data if it doesn't already exist
if (empty( $this->_data ))
{
$query = $this->_buildQuery();
$this->_data = $this->_getList( $query );
}
return $this->_data;
}
}
Model automatically created by Nooku Frameworkadministrator/components/com_hello/views/hellos/view.html.php
jimport( 'joomla.application.component.view' );
class HellosViewHellos extends JView
{
function display($tpl = null)
{
JToolBarHelper::title( JText::_( 'Hello Manager' ), 'generic.png' );
JToolBarHelper::deleteList();
JToolBarHelper::editListX();
JToolBarHelper::addNewX();
// Get data from the model
$items = & $this->get( 'Data');
$this->assignRef('items', $items);
parent::display($tpl);
}
}
Display function automatically created by Nooku Frameworkadministrator/components/com_hello/views/hellos/tmpl/default.php
<form action="index.php" method="post" name="adminForm">
<div id="editcell">
<table class="adminlist">
<thead>
<tr>
<th width="5">
<?php echo JText::_( 'ID' ); ?>
</th>
<th width="20">
<input type="checkbox" name="toggle" value=""
onclick="checkAll(<?php echo count( $this->items ); ?>);" />
</th>
<th>
<?php echo JText::_( 'Greeting' ); ?>
</th>
</tr>
</thead>
<?php
$k = 0;
for ($i=0, $n=count( $this->items ); $i < $n; $i++) {
$row = &$this->items[$i];
$checked = JHTML::_('grid.id', $i, $row->id );
$link=JRoute::_('index.php?option=com_hello&controller=hello&task=edit&cid[]='.$row->id);
?>
<tr class="<?php echo "row$k"; ?>">
<td>
<?php echo $row->id; ?>
</td>
<td>
<?php echo $checked; ?>
</td>
<td>
<a href="<?php echo $link; ?>"><?php echo $row->greeting; ?></a>
</td>
</tr>
<?php
$k = 1 - $k;
}
?>
</table>
</div>
<input type="hidden" name="option" value="com_hello" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="controller" value="hello" />
</form>
administrator/components/com_hello/views/greetings/tmpl/form.php
<form action="<?= @route()?>" method="post" name="adminForm">
<table class="adminlist">
<thead>
<tr>
<th width="5">
<?= @text('NUM'); ?>
</th>
<th width="20">
<input type="checkbox" name="toggle" value="" onclick="checkAll(<?= count(@$greetings); ?>);" />
</th>
<th>
<?= @text('Greeting' ); ?>
</th>
</tr>
</thead>
<tbody>
<? $i = 0; $m = 0; ?>
<? foreach (@$greetings as $greeting) : ?>
<tr class="<?php echo 'row'.$m; ?>">
<td align="center"><?= $i + 1; ?></td>
<td align="center">
<?= @helper('grid.id', $i, $greeting->id); ?>
</td>
<td>
<a href="<?=@route('view=greeting&id='.$greeting->id)?>">
<?= $greeting->greeting; ?>
</a>
</td>
</tr>
<? $i = $i + 1; $m = (1 - $m); ?>
<? endforeach; ?>
</table>
<input type="hidden" name="boxchecked" value="0" />
</form>
administrator/components/com_hello/views/hello/view.html.php
jimport( 'joomla.application.component.view' );
class HellosViewHello extends JView
{
/**
* display method of Hello view
* @return void
**/
function display($tpl = null)
{
//get the hello
$hello =& $this->get('Data');
$isNew = ($hello->id < 1);
$text = $isNew ? JText::_( 'New' ) : JText::_( 'Edit' );
JToolBarHelper::title(JText::_('Hello').':<small><small>['.$text.']</small></small>');
JToolBarHelper::save();
if ($isNew) {
JToolBarHelper::cancel();
} else {
// for existing items the button is renamed `close`
JToolBarHelper::cancel( 'cancel', 'Close' );
}
$this->assignRef('hello', $hello);
parent::display();
}
}
Display function automatically created by Nooku Frameworkadministrator/components/com_hello/views/hello/tmpl/form.php
<form action="index.php" method="post" name="adminForm" id="adminForm">
<div class="col100">
<fieldset class="adminform">
<legend><?php echo JText::_( 'Details' ); ?></legend>
<table class="admintable">
<tr>
<td width="100" align="right" class="key">
<label for="greeting">
<?php echo JText::_( 'Greeting' ); ?>:
</label>
</td>
<td>
<input class="text_area" type="text" name="greeting"
id="greeting" size="32" maxlength="250" value="<?php echo $this->hello->greeting;?>" />
</td>
</tr>
</table>
</fieldset>
</div>
<div class="clr"></div>
<input type="hidden" name="option" value="com_hello" />
<input type="hidden" name="id" value="<?php echo $this->hello->id; ?>" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="controller" value="hello" />
</form>
administrator/components/com_hello/views/hello/tmpl/form.php
<form action="<?= @route('id='.@$greeting->id) ?>" method="post" class="adminform" name="adminForm">
<fieldset class="adminform">
<legend><?= @text('Details' ); ?></legend>
<table class="admintable">
<tr>
<td width="100" align="right" class="key">
<label for="greeting">
<?= @text('Greeting' ); ?>:
</label>
</td>
<td>
<input class="text_area" type="text" name="greeting"
id="greeting" size="32" maxlength="250" value="<?= @$greeting->greeting; ?>" />
</td>
</tr>
</table>
</fieldset>
<input type="hidden" name="id" value="<?= @$greeting->id; ?>" />
</form>