Hi,
i have another blog which was developed by DNN.
now, i want to transfer it Joomla.
i need to add category and article programmatic, but i also got an error when i try to add category:
i have created the test component, in the component entry file:
Code:
defined('_JEXEC') or die;
// Include dependancies
jimport('joomla.application.component.controller');
//echo JPATH_ADMINISTRATOR;
require_once JPATH_ADMINISTRATOR.DS.'components'.DS.'com_categories'.DS.'models'.DS.'category.php';
// Execute the task.
/* $controller = JController::getInstance('Helloworld');
$controller->execute(JRequest::getVar('task',''));
$controller->redirect(); */
//echo "Hello world";
//get categories
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('id, name');
$query->from('#__import_categories');
$db->setQuery($query, 0, 20);
$rows = (array) $db->loadObjectList();
$cateModel = new CategoriesModelCategory();
foreach($rows as $row){
$data = array (
'id' => 0,
'parent_id' => '1',
'extension' => 'com_content',
'title' => $row->name,
'alias' => '',
'note' => '',
'description' => '',
'published' => '1',
'access' => '1',
'metadesc' => '',
'metakey' => '',
'created_user_id' => '0',
'language' => '*',
'rules' =>
array (
'core.create' =>
array (
),
'core.delete' =>
array (
),
'core.edit' =>
array (
),
'core.edit.state' =>
array (
),
'core.edit.own' =>
array (
),
),
'params' =>
array (
'category_layout' => '',
'image' => '',
),
'metadata' =>
array (
'author' => '',
'robots' => '',
),
);
$cateModel->save($data);
echo $row->name . '<br />';
}
error is:
Quote:
the error is in file:
\administrator\components\com_categories\models\category.php
the error code is method "save":
Code:
$table = $this->getTable();
the variable "$table" is false.
so , the problem is there:
Code:
public function getTable($type = 'Category', $prefix = 'CategoriesTable', $config = array()) {
$table = JTable::getInstance($type, $prefix, $config);
//var_dump($table);
return $table;
}
in the JTable::getInstance method:
the $tableClass is : CategoriesTableCategory
but loaded file is : \libraries\joomla\database\table\category.php, in this file the Class name is : JTableCategory, but not CategoriesTableCategory.
the class "CategoriesTableCategory" is in file: /administrator/com_categories/tables/category.php.
can anyone help me where was wrong?
any ideas will be appreciated.