1
votes

I'm building a website that uses Wordpress as the CMS and is built with Yii framework. All the business logic works fine. Most visible pages are filled with content from Wordpress admin and only the user profile section is built with Yii.

My problem is that I would like to reuse the layout of the wordpress pages in the Yii app. Initially I tried to do it in a blank PHP file and everything worked as expected with this code:

<?php
require( '/var/www/wordpress/wp-load.php' );

get_header();
?>

<div>
some content here
</div>

<?php
get_footer();
?>

The problem is that when I make a new layout in Yii so that I can reuse the header and footer it crashes and displays blank page. I tried both with require('/var/www/wordpress/wp-blog-header.php'); and require( '/var/www/wordpress/wp-load.php' );. This is the code I use to load wordpress functionality in Yii but unfortunately it does not work.

<?php /* @var $this Controller */
spl_autoload_unregister(array('YiiBase','autoload'));

define('WP_USE_THEMES', true);
require('/var/www/wordpress/wp-blog-header.php');

//require( '/var/www/wordpress/wp-load.php' );
get_header();

spl_autoload_register(array('YiiBase', 'autoload'));

 ?>

Any help would be much appreciated. Ideally I would like to use get_header() and get_footer() wordpress functions in Yii layouts/views.

Thanks

UPDATE

I checked Apache logs and it seems that the following error is logged when I try to open the page in my browser: PHP Fatal error: Call to a member function get() on a non-object in /var/www/wordpress/wp-includes/query.php on line 27 Also when I comment out the get_header(); row the page opens without any errors (and without any styling too). So something prevents get_header() to work property in Yii.

1

1 Answers

0
votes

I ended up adding require( '/var/www/wordpress/wp-load.php' ); in the Yii's index.php file just before the initialization code. Then I was able to use all WordPress functions in my project. This helped me reuse the header and footer layout from WordPress in Yii using the get_header() and get_footer() functions.