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
使用 Component M Multisite Master 说明手册
By wipaporn Wed 20 Feb 2019 4:30 pm Board Chinese Language - 简体中文
0
19950
Wed 20 Feb 2019 4:30 pm By wipaporn
使用 Component M Multisite Client 说明手册
By wipaporn Wed 20 Feb 2019 4:06 pm Board Chinese Language - 简体中文
0
20798
Wed 20 Feb 2019 4:06 pm By wipaporn
Features Review : M MultiSite Content client Komponen untuk merekodkan Nama Domain Master Site
By abdkode Wed 20 Feb 2019 3:51 pm Board Bahasa Language
0
8060
Wed 20 Feb 2019 3:51 pm By abdkode
使用Module MDFiles Popular 说明手册
By wipaporn Wed 20 Feb 2019 3:35 pm Board Chinese Language - 简体中文
0
24338
Wed 20 Feb 2019 3:35 pm By wipaporn
Features Review : MDFiles Documents membantu menghubungkan artikel ke Component MDFiles
By abdkode Wed 20 Feb 2019 3:33 pm Board Bahasa Language
0
4695
Wed 20 Feb 2019 3:33 pm By abdkode
使用 Module MDFiles Featured 说明手册
By wipaporn Wed 20 Feb 2019 3:04 pm Board Chinese Language - 简体中文
0
25116
Wed 20 Feb 2019 3:04 pm By wipaporn
使用Module MDFiles Categories 说明手册
By wipaporn Wed 20 Feb 2019 2:31 pm Board Chinese Language - 简体中文
0
21882
Wed 20 Feb 2019 2:31 pm By wipaporn
使用 Module MDfiles recent 说明手册
By wipaporn Wed 20 Feb 2019 2:29 pm Board Chinese Language - 简体中文
0
24086
Wed 20 Feb 2019 2:29 pm By wipaporn
使用Component MDFiles说明手册
By wipaporn Wed 20 Feb 2019 12:10 pm Board Chinese Language - 简体中文
0
10784
Wed 20 Feb 2019 12:10 pm By wipaporn
使用 Component MJForm 说明手册
By wipaporn Wed 20 Feb 2019 12:03 pm Board Chinese Language - 简体中文
0
23180
Wed 20 Feb 2019 12:03 pm By wipaporn
Features Review : Plugin Editors XTD Multicontent untuk mengeluarkan artikel dari Master Site ke Web Clien
By abdkode Tue 19 Feb 2019 6:52 pm Board Bahasa Language
0
6501
Tue 19 Feb 2019 6:52 pm By abdkode
Features Review : Mod MDFiles Popular modul menyenaraikan fail popular
By abdkode Tue 19 Feb 2019 5:41 pm Board Bahasa Language
0
5460
Tue 19 Feb 2019 5:41 pm By abdkode
Features Review : Mod MDFiles Featured memaparkan fail-fail yang dipilih dari MDFile untuk dipaparkan pada Joomla
By abdkode Tue 19 Feb 2019 4:39 pm Board Bahasa Language
0
2763
Tue 19 Feb 2019 4:39 pm By abdkode
Features Review : Components Mjform komponen untuk membuat borang laman web
By abdkode Tue 19 Feb 2019 3:23 pm Board Bahasa Language
0
2637
Tue 19 Feb 2019 3:23 pm By abdkode
Mod MDFiles Popular 모듈 소개 MDFile에서 파일을 가져와 표시
By wipaporn Fri 15 Feb 2019 6:06 pm Board korean Language - 한국어
0
6427
Fri 15 Feb 2019 6:06 pm By wipaporn
MDFiles Featured modules를 소개하면 MDFile에서 파일을 가져와 보여준다.
By wipaporn Fri 15 Feb 2019 6:06 pm Board korean Language - 한국어
0
6073
Fri 15 Feb 2019 6:06 pm By wipaporn
마스터 사이트에서 Web Client로 문서를 끌어오기 위한 플러그인인 Editors XTD Multicontent를 소개한다.
By wipaporn Fri 15 Feb 2019 5:48 pm Board korean Language - 한국어
0
1994
Fri 15 Feb 2019 5:48 pm By wipaporn
Joomla 1.5를 Joomla 2.5, 3.X로 업그레이드하기 위한 MJUpgrade 소개
By wipaporn Fri 15 Feb 2019 5:36 pm Board korean Language - 한국어
0
2363
Fri 15 Feb 2019 5:36 pm By wipaporn
MApplication Form Components를 소개한다. 구직 신청서는 웹사이트를 통해 작성된다.
By wipaporn Fri 15 Feb 2019 5:27 pm Board korean Language - 한국어
0
2184
Fri 15 Feb 2019 5:27 pm By wipaporn
Joomla 웹사이트 방문수를 집계하기 위한 "Mod vinaora visitors counter" 소개
By wipaporn Fri 15 Feb 2019 5:09 pm Board korean Language - 한국어
0
2099
Fri 15 Feb 2019 5:09 pm By wipaporn