User Rating: 2 / 5

Star ActiveStar ActiveStar InactiveStar InactiveStar Inactive
 

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
3 Investment Worthly in Thaland
By wannapat Tue 19 Mar 2019 4:38 pm Board Chinese Language - 简体中文
0
15624
Tue 19 Mar 2019 4:38 pm By wannapat
Features Review : Plugin Addons Payment Omise untuk membuat pembayaran melalui Omise
By abdkode Mon 11 Mar 2019 6:58 pm Board Bahasa Language
0
2221
Mon 11 Mar 2019 6:58 pm By abdkode
Features Review : Memperkenalkan Mooziicart untuk Joomla
By abdkode Thu 07 Mar 2019 7:06 pm Board Bahasa Language
0
2616
Thu 07 Mar 2019 7:06 pm By abdkode
Features Review : Plugin M Product Match untuk menghungkan produk dengan artikel
By abdkode Thu 07 Mar 2019 6:19 pm Board Bahasa Language
0
2701
Thu 07 Mar 2019 6:19 pm By abdkode
Features Review : Module MD Client History modul memapar sajarah yang telah masuk
By abdkode Tue 05 Mar 2019 7:15 pm Board Bahasa Language
0
1906
Tue 05 Mar 2019 7:15 pm By abdkode
Features Review : Plugin M Animate Number untuk memaparkan nombor yang bergerak
By abdkode Mon 04 Mar 2019 7:02 pm Board Bahasa Language
0
2138
Mon 04 Mar 2019 7:02 pm By abdkode
Features Review : Plugin PayToRead untuk mempaparkan teks hanya sebahagian
By abdkode Mon 04 Mar 2019 7:01 pm Board Bahasa Language
0
2334
Mon 04 Mar 2019 7:01 pm By abdkode
Features Review : Component MFacebook untuk membantu pendaftaran laman web dgn Facebook
By abdkode Mon 04 Mar 2019 6:57 pm Board Bahasa Language
0
2851
Mon 04 Mar 2019 6:57 pm By abdkode
Features Review : MJClone untuk mengklon laman web joomla dan backup
By abdkode Thu 28 Feb 2019 6:59 pm Board Bahasa Language
0
3113
Thu 28 Feb 2019 6:59 pm By abdkode
Features Review : Module Mrelated Article Specific Category untuk menyimpan sejarah lawatan
By abdkode Thu 28 Feb 2019 6:48 pm Board Bahasa Language
0
1839
Thu 28 Feb 2019 6:48 pm By abdkode
Features Review : Plugin MLinkarticle untuk menghubungkan konten artikel kepada artikel yang berkaitan
By abdkode Tue 26 Feb 2019 6:37 pm Board Bahasa Language
0
2558
Tue 26 Feb 2019 6:37 pm By abdkode
Features Review : Plugin Authentication untuk login Joomla dengan phpBB
By abdkode Tue 26 Feb 2019 6:29 pm Board Bahasa Language
0
3363
Tue 26 Feb 2019 6:29 pm By abdkode
Features Review : untuk menghasilkan link memuat naik video pada artikel, Joomla 2.5, 3.x
By abdkode Tue 26 Feb 2019 5:26 pm Board Bahasa Language
0
2070
Tue 26 Feb 2019 5:26 pm By abdkode
Features Review : Plugin MVDO untuk memuat naik video Youtube dan Clipmass
By abdkode Mon 25 Feb 2019 5:54 pm Board Bahasa Language
0
2341
Mon 25 Feb 2019 5:54 pm By abdkode
Features Review : Content Msocial untuk berkongsi kandungan artikel ke Facebook, Twitter, Google Plus dan Line
By abdkode Mon 25 Feb 2019 4:56 pm Board Bahasa Language
0
1967
Mon 25 Feb 2019 4:56 pm By abdkode
Features Review : Module Mod slideshowck untuk membantu memaparkan imej dan video Youtube secara slaid
By abdkode Mon 25 Feb 2019 2:19 pm Board Bahasa Language
0
2032
Mon 25 Feb 2019 2:19 pm By abdkode
Features Review : Mod MD recent untuk menunjukkan Papan phpbb pada Joomla.
By abdkode Fri 22 Feb 2019 6:59 pm Board Bahasa Language
0
2635
Fri 22 Feb 2019 6:59 pm By abdkode
Features Review : Mod vinaora visitors counter untuk menghitungkan pelewat laman web di joomla
By abdkode Fri 22 Feb 2019 4:17 pm Board Bahasa Language
0
2573
Fri 22 Feb 2019 4:17 pm By abdkode
Features Review : Components MApplication Form untuk permohonan pekerjaan melalui laman web.
By abdkode Fri 22 Feb 2019 3:25 pm Board Bahasa Language
0
2810
Fri 22 Feb 2019 3:25 pm By abdkode
Features Review : Components MComponentgen & M Packet untuk membantu dengan Menjana Komponen, Modul, Plugin
By abdkode Fri 22 Feb 2019 2:26 pm Board Bahasa Language
0
2725
Fri 22 Feb 2019 2:26 pm By abdkode