Joomla - MVC: Creating Controller and Model for Back End



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


Tag: joomla, MVC, component, pattern, controller, model Category: PHP Framework Post : February 06th 2008 Read: 4,341 Bookmark and Share

blog comments powered by Disqus