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
Features Review : Mod MDFiles Categories bantu memaparkan Kategori MDFiles
By abdkode Thu 14 Feb 2019 6:13 pm Board Bahasa Language
0
7544
Thu 14 Feb 2019 6:13 pm By abdkode
Introducing Mod MDFiles Featured MDFiles popular modules bring files from MDFile to show.
By wipaporn Wed 13 Feb 2019 6:51 pm Board English Language
0
16590
Wed 13 Feb 2019 6:51 pm By wipaporn
Introducing MDFiles Featured modules bring files from MDFile to show
By wipaporn Wed 13 Feb 2019 6:34 pm Board English Language
0
2868
Wed 13 Feb 2019 6:34 pm By wipaporn
Introducing Editors XTD Multicontent, a plugin for pulling articles from Master Site into Web Clien.
By wipaporn Wed 13 Feb 2019 6:05 pm Board English Language
0
6320
Wed 13 Feb 2019 6:05 pm By wipaporn
Introducing MJUpgrade for upgrading Joomla 1.5 to Joomla 2.5, 3.X
By wipaporn Wed 13 Feb 2019 6:03 pm Board English Language
3
1816
Mon 13 Apr 2020 7:01 pm By prmindphp
Introducing the Mod vinaora visitors counter for counting website visits in joomla
By wipaporn Wed 13 Feb 2019 6:01 pm Board English Language
0
1630
Wed 13 Feb 2019 6:01 pm By wipaporn
Introducing MVDO plugin for uploading Youtube videos and Clipmass
By wipaporn Wed 13 Feb 2019 5:58 pm Board English Language
0
1463
Wed 13 Feb 2019 5:58 pm By wipaporn
Introducing MD Gallery Components for creating photo galleries on Joomla 3.x website
By wipaporn Wed 13 Feb 2019 5:54 pm Board English Language
13
9183
Tue 31 Mar 2020 6:37 pm By prmindphp
Plugin MD Watermark 소개, 자동 워터마킹용 플러그
By wipaporn Wed 13 Feb 2019 3:53 pm Board korean Language - 한국어
0
2644
Wed 13 Feb 2019 3:53 pm By wipaporn
PayToRead 소개. 플러그인은 일부 텍스트만 보여준다.
By wipaporn Wed 13 Feb 2019 3:51 pm Board korean Language - 한국어
0
1988
Wed 13 Feb 2019 3:51 pm By wipaporn
Facebook에 웹 사이트 회원 등록을 돕기 위한 Component MFacebook 소개
By wipaporn Wed 13 Feb 2019 3:48 pm Board korean Language - 한국어
0
1363
Wed 13 Feb 2019 3:48 pm By wipaporn
"Module Mrelated Article Specific Category" (저장소 검색 이력)을 소개한다
By wipaporn Wed 13 Feb 2019 3:46 pm Board korean Language - 한국어
1
3962
Thu 27 Feb 2020 10:20 pm By mindphp
MDFiles Categories Module을 소개한다.
By wipaporn Wed 13 Feb 2019 3:44 pm Board korean Language - 한국어
0
774
Wed 13 Feb 2019 3:44 pm By wipaporn
MDFile의 파일을 보여주는 mod mdfile recent 모듈 소개
By wipaporn Wed 13 Feb 2019 3:41 pm Board korean Language - 한국어
0
967
Wed 13 Feb 2019 3:41 pm By wipaporn
Joomla용 MDFile Components를 소개하고, 웹사이트에서 문서 파일을 다운로드하는 것을 돕는다.
By wipaporn Wed 13 Feb 2019 3:37 pm Board korean Language - 한국어
0
338
Wed 13 Feb 2019 3:37 pm By wipaporn
介绍joomla的components mdfile,帮助在网站上下载文档文件。
By wipaporn Wed 13 Feb 2019 3:32 pm Board Chinese Language - 简体中文
0
10859
Wed 13 Feb 2019 3:32 pm By wipaporn
介绍mod mdfile recent模块以显示mdfile中的文件
By wipaporn Wed 13 Feb 2019 3:29 pm Board Chinese Language - 简体中文
0
16548
Wed 13 Feb 2019 3:29 pm By wipaporn
介绍mod mdfiles categories模块从mdfile中引入类别。
By wipaporn Wed 13 Feb 2019 3:27 pm Board Chinese Language - 简体中文
0
22660
Wed 13 Feb 2019 3:27 pm By wipaporn
介绍Module Mrelated Article Specific Category。存储浏览历史记录。
By wipaporn Wed 13 Feb 2019 3:23 pm Board Chinese Language - 简体中文
0
872
Wed 13 Feb 2019 3:23 pm By wipaporn
介绍Component mFaceBook以帮助在Facebook上注册网站成员资
By wipaporn Wed 13 Feb 2019 3:20 pm Board Chinese Language - 简体中文
0
310
Wed 13 Feb 2019 3:20 pm By wipaporn