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: Select all
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 />';
}
the error is in file:PHP Fatal error: Call to a member function setLocation() on a non-object in D:\CANADA\joomla-learning.testing.our-projects.info\administrator\components\com_categories\models\category.php on line 364
PHP Stack trace:
PHP 1. {main}() D:\CANADA\joomla-learning.testing.our-projects.info\index.php:0
PHP 2. JSite->dispatch() D:\CANADA\joomla-learning.testing.our-projects.info\index.php:42
PHP 3. JComponentHelper::renderComponent() D:\CANADA\joomla-learning.testing.our-projects.info\includes\application.php:197
PHP 4. JComponentHelper::executeComponent() D:\CANADA\joomla-learning.testing.our-projects.info\libraries\joomla\application\component\helper.php:351
PHP 5. require_once() D:\CANADA\joomla-learning.testing.our-projects.info\libraries\joomla\application\component\helper.php:383
PHP 6. CategoriesModelCategory->save() D:\CANADA\joomla-learning.testing.our-projects.info\components\com_helloworld\helloworld.php:116
\administrator\components\com_categories\models\category.php
the error code is method "save":
Code: Select all
$table = $this->getTable();
so , the problem is there:
Code: Select all
public function getTable($type = 'Category', $prefix = 'CategoriesTable', $config = array()) {
$table = JTable::getInstance($type, $prefix, $config);
//var_dump($table);
return $table;
}
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.