Tuesday, 7 August 2012

Joomla 2.5 how to add a button with action to my module in the MVC format

Here's the answer to a fairly simple task - which is how to add a form and button inside a module.  Keeping within our nice MVC format.

Here's some of the searches I've done to research the solution for this.

joomla should a mysql UPDATE query be in MODEL of Controller

joomla development how to use a POST form in module

Retrieving Data for GET & Post - Joomla Development

my module has these files


 MODEL - this goes in  helper.php

Inside your CLASS bracket add

     public function setCancelWarnings($shift_id){
      $db = &JFactory::getDBO();

      $query  = "UPDATE #__pf_time_tracking ";
      $query .= "SET `dShftChked` = '1' ";
      $query .= "WHERE id =$shift_id ";
      echo "

CONTROLLER - this goes in modules/mod_PRSwarnings/mod_PRSwarnings.php

!! enter below the current code on your contoller page.

$edit_warnings = JRequest::getVar('edit_warnings');
// echo "EDIT - $edit_warnings

if($edit_warnings=='Cancel Warninig'){
            $shift_id = JRequest::getVar('shift_id', '', 'POST');
            $setCancelWarnings = ModPRSwarnings::setCancelWarnings($shift_id);

VIEW  - this goes in tmpl/default.php

put this where you want the form to be displayed

 echo "


Although the code above is specific to my website I think it will be useful to others. As it shows a good demonstration of the logic of MVC in Joomla.  I welcome any discussion you may have on this.  Would you have done it differently.

No comments: