Importing posts from WordPress into Yii
Riding the wave of the previous post, I decided to play around with Yii and try porting this site, posts and pages included, over to Yii.
So we’ve got a MySQL server with two databases:
- wordpress
- yii
Task: move all the posts from the WordPress database into the Yii database.
Done with the following query:
insert into yii.article (id, title, body, slug, created_at, updated_at, published_at, author_id, status)
select ID,post_title,post_content,post_name,unix_timestamp(post_date),unix_timestamp(post_modified),unix_timestamp(post_date),1,1
from wordpress.wp_posts where post_status = 'publish' and post_type = 'post';
As a result you can already see all the blog’s posts styled the Yii way:

Left is to edit frontend/views/article/view.php and fix how the post body gets output. Find this line:
<?php echo $model->body ?>
And change it to this:
<?php echo preg_replace('/\n(\s*\n)/','<p>',$model->body) ?>