织梦dedecms转Joomla!——文章目录的数据库转存

<?php

require_once JPATH_ADMINISTRATOR . '/components/com_categories/models/category.php';
require_once JPATH_ADMINISTRATOR . '/components/com_categories/tables/category.php';//引入2个目录组件的文件,以便使用<span style="font-family: Arial, Helvetica, sans-serif;">CategoriesModelCategory </span>


$new_category = new CategoriesModelCategory ();


$options = array (
		'driver' => 'mysqli',
		'host' => 'localhost',
		'user' => 'root',
		'password' => 'pwd',
		'database' => 'dedecms',
		'prefix' => 'dede_' 
);

$db = JDatabaseDriver::getInstance ( $options );  //通过Joomla!的数据库类来读取dedecms的类表
 
$query = $db->getQuery(true);


$query->select($db->quoteName(array('id','typename','typedir')))
	->from($db->quoteName('#__arctype'))
	->order('sortrank ASC')
	->where($db->quoteName('reid') . ' = '. $db->quote('0'))
        ->setLimit('8','47');   //最好不要一次调用太多,以防超时

$db->setQuery($query);

$results = $db->loadObjectList();

foreach ($results as $sanjikeshi){
	
	$keshiname3 = substr($sanjikeshi->typedir,strrpos($sanjikeshi->typedir,'/')+1,strlen($sanjikeshi->typedir)-strrpos($sanjikeshi->typedir,'/'));
	
	$data3 = array (
			'id' => 0,
			'hits' => '0',
			'parent_id' => '79',
			'extension' => 'com_content',
			'title' => $sanjikeshi->typename,
			'alias' => $keshiname3,
			'note' => $sanjikeshi->id, //把原来的ID存入备注中,方便之后存入文章
			'published' => '1',
			'access' => '1',
			'language' => '*'
	);
	
	if($new_category->save($data3)){
		var_dump($sanjikeshi->typename.'save to db ');
	}else {
		var_dump($sanjikeshi->typename.'fail ');
	}
	//以下是把这层目录的子目录读出来,然后存到这层子目录下
	$par_id = $new_category->getState('category.id');
	
	$query2 = $db->getQuery(true);
	$query2->select($db->quoteName(array('id','typename','typedir')))
		->from($db->quoteName('#__arctype'))
		->order('sortrank ASC')
		->where($db->quoteName('reid') . ' = '. $sanjikeshi->id);
	$db->setQuery($query2);	
	$results4 = $db->loadObjectList();

	foreach($results4 as $sijikeshi){
		$keshiname4 = substr($sijikeshi->typedir,strrpos($sijikeshi->typedir,'/')+1,strlen($sijikeshi->typedir)-strrpos($sijikeshi->typedir,'/'));
		$data4 = array (
				'id' => 0,
				'hits' => '0',
				'parent_id' => $par_id,
				'extension' => 'com_content',
				'title' => $sijikeshi->typename,
				'alias' => $keshiname4,
				'note' => $sijikeshi->id,
				'published' => '1',
				'access' => '1',
				'language' => '*'
		);
	
		if ($new_category->save ( $data4 )) {
			var_dump($sijikeshi->typename . 'save to db ');
		} else {
			var_dump( $sijikeshi->typename . 'fail');
		}
	}
}


?>


核心技术2个:

  • 使用CategoriesModelCategory 类来自动写入数据库
  • 使用JDatabaseDriver来都去原来dedecms中的数据

这只是个小demo,离使用还有差距

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值