Hi,
I created custom component using this video tutorial..
https://www.youtube.com/watch?v=SEUxm01dgE8&index=4&list=PLLi1ciqQAf8QwFHLQmVsrU7QuDXqJntyC
and I created content versioning in our custom component.
path where we save data - (administrator/components/com_helloworld/models/helloworld.php)
Here is my code:
save function working fine but version data are not saving in database #__ucm_history
we save version data using this .. (administrator/components/com_helloworld/tables/helloworld.php)
but content version are not save in database table #__ucm_history and in popup window of 'Versions' Tab data is blank. (like:- in attachment)
Please help me.....Thanks
I created custom component using this video tutorial..
https://www.youtube.com/watch?v=SEUxm01dgE8&index=4&list=PLLi1ciqQAf8QwFHLQmVsrU7QuDXqJntyC
and I created content versioning in our custom component.
path where we save data - (administrator/components/com_helloworld/models/helloworld.php)
Here is my code:
<?php
//No direct access to this file
defined('_JEXEC') or die('Restricted Access');
jimport('joomla.filesystem.file');
class HelloworldModelHelloworld extends JModelForm
{
/**
* The type alias for this content type.
*/
public $typeAlias = 'com_helloworld.helloworld';
function getForm($data = array(),$loadData = true) {
$options = array('control' => 'jform', 'load_data' => $loadData);
$form = $this->loadForm('com_helloworld.helloworld','helloworld', $options);
if(empty($form)) {
return false;
}
return $form;
}
function save($data) {
$db = JFactory::getDbo();
$obj = (object) $data;
if(!empty($_FILES['jform']['name']['company_logo'])) {
$ext = JFile::getExt($_FILES['jform']['name']['company_logo']);
$obj->company_logo = md5($_FILES['jform']['name']['company_logo'].time()).'.'.$ext;
$dest = HOSTING_IMAGEPATH.$obj->company_logo;
//echo "<pre>";print_r($_FILES);die;
JFile::copy($_FILES['jform']['tmp_name']['company_logo'],$dest);
}
try {
if($obj->id) {
$db->updateObject('#__mdhosting_companies', $obj, 'id');
} else {
$db->insertObject('#__mdhosting_companies', $obj, 'id');
}
} catch (RuntimeException $exc) {
$this->setError($exc->getMessage());
return false;
}
return true;
}
public function getItem() {
$pk = JRequest::getVar('cid');
if(is_array($pk)) {
$pk = $pk[0];
}
if($pk == '') {
return false;
}
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*')->from('#__mdhosting_companies')->where($db->quoteName('id').'='.$db->quote($pk));
$db->setQuery($query);
$db->query();
return $db->loadObject();
}
protected function loadFormData() {
$data = $this->getItem();
return $data;
}
function delete($id) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
try {
$query->delete('#__mdhosting_companies')->where($db->quotename('id').'='.$db->quote($id));
$db->setQuery($query);
$db->execute();
} catch (RuntimeException $exc) {
$this->setError($exc->getMessage());
return false;
}
return true;
}
}
save function working fine but version data are not saving in database #__ucm_history
we save version data using this .. (administrator/components/com_helloworld/tables/helloworld.php)
<?php
//No direct access to this file
defined('_JEXEC') or die('Restricted Access');
class HelloworldTableHelloworld extends JTable
{
public function __construct(&$db)
{
parent::__construct('#__mdhosting_companies', 'id', $db);
JTableObserverTags::createObserver($this, array('typeAlias' => 'com_helloworld.helloworld'));
JTableObserverContenthistory::createObserver($this, array('typeAlias' => 'com_helloworld.helloworld'));
}
}
after editing data constructor are not calling , and we insert 1 record in #__content_types...
INSERT INTO `#__content_types` (`type_id`, `type_title`, `type_alias`, `table`, `rules`, `field_mappings`, `router`, `content_history_options`)
VALUES
(NULL,
'Helloworld',
'com_helloworld.helloworld',
'{"special":{"dbtable":"#__mdhosting_companies","key":"id","type":"Helloworld","prefix":"HelloworldTable"}}',
'', '', '', '');
but content version are not save in database table #__ucm_history and in popup window of 'Versions' Tab data is blank. (like:- in attachment)
Please help me.....Thanks