Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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'));
require( '/var/www/wordpress/wp-load.php' );
get_header();

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

 ?>

All I see is a completely blank page (no markup).

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.

share|improve this question
    
Disable all the plugins and check again. –  Wyck Jan 7 '13 at 3:41
add comment

2 Answers

In your header.php you are probably using wp_title(). This one requires at least two global variables: $wpdb (the get_query_var() call) and $wp_locale, on singular views a global $post object too.

So you have to create these variables, or set wp_title() in a conditional, like this:

if ( ! empty ( $GLOBALS['wpdb'] ) )
    wp_title();
share|improve this answer
    
Then how does the same code works outside of Yii framework? –  Pavel Nikolov Jan 7 '13 at 7:17
    
@PavelNikolov No idea, $wpdb is required as you can see by the source code. –  toscho Jan 7 '13 at 11:40
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.