phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Joomla - MVC: Creating Controller and Model for Back End

Tag: joomla, MVC, component, pattern, controller, model   Category: PHP Framework
post: 06 Feb 2008 read: 1,538


Joomla Back End MVC Step By Step Tutorial - Part 2: At previous post, we have talked about enter point use MVC. Now, we will create a controller and model (for retrieve data). What task this controller? You can read here. Create a file named "controller.php" within Joomla\administrator\components\com_hello. Enter following code:

joomla mvc back end controller


<?
defined('_JEXEC') or die('Restricted Access');
jimport('joomla.application.component.controller');

class HelloController extends JController
{
  function __construct ($default = array())
  {
  	parent::__construct( $default );
  }
  function showHellos()
  {
  	global $options;
	$db =& JFactory::getDBO();
	$query = "SELECT * FROM #__hello";
	$db->setQuery ( $query);
	$rows = $db->loadObjectList();
	if ($db->getErrorNum())
	{
	  echo $db->stderr();
	  return false;
	}
  	HTML_hellos::showHellos( $option, $rows );
  }
}
?>


Series this article:
Joomla - MVC: Reorganizing Back End Code
Joomla - MVC: Creating Controller and Model for Back End
Joomla - MVC: Creating View for Back End
Joomla - MVC: Adding Pagination for Back End
Joomla - MVC: Adding Element Paginating for Back End
Joomla - MVC: Creating Form Input Data for Back-End
Joomla - MVC: Saving Data for Back End
Joomla - MVC: Editing Data for Back-End
Joomla - MVC: Adding Delete Function at Back-End
Joomla - MVC: Controlling Publish State for Back-End

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


619
posting