JTable - has created a Class that allows you to access and manipulate data in a database table easier. For fundamental processes such as the retrieval of records. Emptying the table and Reducing the work in the Model into it. for use JTable in the Component of us also have the controllers models views must create the tables added for storing class files of JTable named class is similar to the naming controllers models views. Component is a name followed by the word Table and closed with a filename such as tables, create a file in a folder com_helloworld. hello.php HelloworldTableHello and class names are assigned to the class JTable extends and construct the building

 

com_helloworld/tables/hello.php

 

inside the hello.php file insert the code below

 

<?php
class HelloworldTableHello extends JTable
{
public function __construct(&$db)
{
        parent::__construct('#__tablename', 'id', $db);
{
}

 

Now we need to enhance and adjust the codes on Controllers folder

 

In building a controller would normally extends from class JControllerLegacy. In fact, we also have a class that extends another 2 class. JControllerAdmin controller is ideal for managing list of data items.

 

If we select extends from the top of a class, a function that allows you to create custom diminished. Save time coding

 

Sample controller (can add, edit) using a 2 function

 

Modify the codes on the file php under controllers folder

 

public function display($cachable = false, $urlparams = array())
{
         $task = JRequest::getVar('task');
      if($task == 'add' || $task == 'edit') {
              $view = $this->getView();
            $view->setModel($this->getModel(), true);
    } else {
            $view = $this->getView(ucfirst($this->controller).'s');
            $view->setModel($this->getModel(ucfirst($this->controller).'s'), true);
     }
 $view->display();
}

 

 for recording

 

<?php
public function Save () 
  { 
// prevent attacks from outside your system. 
JSession :: CheckToken ()  or die( JText :: _ ( 'JINVALID_TOKEN' )); 

// run the Object Model  
$model = $this->getModel();

// a value stored in variable form. $ Data 
$data  = $this->input->post->get('jform', array(), 'array');
 if (!$model->save($data))


// if he fails the error 
$this->setError(JText::sprintf('Failed', $model->getError()));
$this->setMessage($this->getError(), 'error');

// moved to a statement. 
 $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&c=example'
)
);
          return false ; 
    } 

     // message if He achieved 
       $this->setMessage(JText::_('Success'));

    // move to the registration statement. 
    $this->setRedirect(
    JRoute::_('index.php?option=' . $this->option . '&c=example'
      )
   );
return true;
   }
}

 

the creation of a model usually created 2 model. First it retrieves the page from the list extends class JModelList. The second extends class information in the form of JModelAdmin JModelForm JModelLegacy which normally takes the form of JModelLegacy but if we had to switch to using xml JModelForm but from those used JModelAdmin be super useful.

 

Modify the php file under the Models folder

 

<? PHP defined 
( '_JEXEC' )  or Die (); 
Class ExampleModelExample extends JModelAdmin 


// extract data from xml file to create a form. 
public function getForm($data = array(), $loadData = true) 
{
$form = $this->loadForm('com_example.example', 'example', array('control' => 'jform', 'load_data' => $loadData));
return $form;
}

// keep critical values ​​for the lead. In another function, such as the id of the table. 
protected function populateState()
{
  $cid = JRequest::getVar('cid');
  $this->setState('id', $cid[0]);
}

// out the chart to the form. 
protected function loadFormData()
{
      $data = JFactory::getApplication()->getUserState('com_example.edit.example', array());
if (empty($data)) {
$data = $this->getItem();
}
return $data;
}

 // call the JTable Object  
public function getTable($name = 'Example', $prefix = 'ExampleTable', $options = array()) 
{
    return parent::getTable($name, $prefix, $options);
  }
}
Recent Topics
Subject
Post Reply
Open
Recent
Report A Problem Using The Square Root Calculation Program
By Thanapoom1514 Wed 29 Nov 2023 10:46 am Board English Language
0
1445
Wed 29 Nov 2023 10:46 am By Thanapoom1514 View Topic Report A Problem Using The Square Root Calculation Program
Cyberpanel PHP8.2
By Anonymous Tue 28 Nov 2023 9:44 am Board English Language
1
661
Tue 28 Nov 2023 10:05 am By mindphp View Topic Cyberpanel PHP8.2
Guide to Domain Hosting: Types, Purchasing, and Current Services
By Watkinsayden81 Wed 08 Nov 2023 3:32 pm Board English Language
0
535
Wed 08 Nov 2023 3:32 pm By Watkinsayden81 View Topic Guide to Domain Hosting: Types, Purchasing, and Current Services
Report A Problem Using Program Calculates Tax Withholding
By Thanapoom1514 Thu 26 Oct 2023 11:19 am Board English Language
0
983
Thu 26 Oct 2023 11:19 am By Thanapoom1514 View Topic Report A Problem Using Program Calculates Tax Withholding
Expert Programming Assignment Help: Your Solution to Coding Challenges
By alfredaharnish Thu 19 Oct 2023 1:33 pm Board English Language
1
547
Sat 04 Nov 2023 7:57 pm By Anonymous View Topic Expert Programming Assignment Help: Your Solution to Coding Challenges
Report A Problem Using The Map Location Search Program
By Thanapoom1514 Thu 14 Sep 2023 4:47 pm Board English Language
1
1445
Tue 19 Sep 2023 4:17 pm By veras View Topic Report A Problem Using The Map Location Search Program
setup microsoft 365
By matthewtaylor39 Tue 05 Sep 2023 3:59 pm Board English Language
1
591
Mon 23 Oct 2023 7:14 pm By veras View Topic setup microsoft 365
Report a problem using Program Exchange Rate
By Thanapoom1514 Wed 21 Jun 2023 4:54 pm Board English Language
0
1958
Wed 21 Jun 2023 4:54 pm By Thanapoom1514 View Topic Report a problem using Program Exchange Rate
Where can I download most recent version of MDUpgrade?
By filipetorres Wed 24 May 2023 9:30 pm Board English Language
3
903
Thu 25 May 2023 4:41 pm By mindphp View Topic Where can I download most recent version of MDUpgrade?
How to plan your E-commerce website
By rachaelwools Mon 08 May 2023 5:48 pm Board English Language
1
742
Mon 15 May 2023 4:42 pm By Reginaler View Topic How to plan your E-commerce website
Report a problem, delete usage data in the domain checker program.
By Thanapoom1514 Mon 17 Apr 2023 4:58 pm Board English Language
0
731
Mon 17 Apr 2023 4:58 pm By Thanapoom1514 View Topic Report a problem, delete usage data in the domain checker program.
Report a problem using the QR code generator
By Thanapoom1514 Mon 03 Apr 2023 11:50 am Board English Language
0
826
Mon 03 Apr 2023 11:50 am By Thanapoom1514 View Topic Report a problem using the QR code generator
Report a problem using the domain checker program
By Thanapoom1514 Thu 30 Mar 2023 12:23 pm Board English Language
0
1760
Thu 30 Mar 2023 12:23 pm By Thanapoom1514 View Topic Report a problem using the domain checker program
Choosing The Perfect Venue for Your Special Day in Phuket
By Justastoryteller Wed 29 Mar 2023 9:35 am Board English Language
1
851
Tue 25 Apr 2023 5:40 pm By davidmikejohn View Topic Choosing The Perfect Venue for Your Special Day in Phuket
How to Decorate Your Apartment in Bangkok on a Budget
By pechevill Tue 28 Mar 2023 2:46 pm Board English Language
1
960
Wed 29 Mar 2023 2:43 pm By Justastoryteller View Topic How to Decorate Your Apartment in Bangkok on a Budget
Report a problem using the EAN-13 barcode generator program
By Thanapoom1514 Tue 28 Mar 2023 11:08 am Board English Language
0
1642
Tue 28 Mar 2023 11:08 am By Thanapoom1514 View Topic Report a problem using the EAN-13 barcode generator program
Report a problem using the program to calculate the air conditioning (BTU)
By Tookta Tue 28 Feb 2023 10:13 am Board English Language
0
2216
Tue 28 Feb 2023 10:13 am By Tookta View Topic Report a problem using the program to calculate the air conditioning (BTU)
Report an issue with the taxi rate calculation program
By flook Tue 21 Feb 2023 11:59 am Board English Language
0
1508
Tue 21 Feb 2023 11:59 am By flook View Topic Report an issue with the taxi rate calculation program
Report a problem using the Program for calculating land price per unit
By Thanapoom1514 Mon 20 Feb 2023 10:54 am Board English Language
0
2815
Mon 20 Feb 2023 10:54 am By Thanapoom1514 View Topic Report a problem using the Program for calculating land price per unit
Report a problem using the total land price calculation program
By Thanapoom1514 Mon 20 Feb 2023 10:24 am Board English Language
0
1385
Mon 20 Feb 2023 10:24 am By Thanapoom1514 View Topic Report a problem using the total land price calculation program