2009-10-01 53 views
3

我有一個用Symfony 1.2構建的網站。我正在嘗試將Wordpress 2.8.4集成到它中以支持我的博客。我遵循http://www.theodo.fr/blog/2009/03/integrate-wordpress-into-symfony/的說明,其中包括http://www.theodo.fr/blog/2009/03/integrate-wordpress-into-symfony/comment-page-1/#comment-573評論中的2個步驟。我的actions.class.php文件看起來像這樣:將Wordpress與Symfony集成

<?php 
class sfWordpressActions extends sfActions 
{ 
    public function executeIndex(sfWebRequest $request) 
    { 

    // Don't load symfony's I18N 
    $standard_helpers = sfConfig::get('sf_standard_helpers'); 
    $standard_helpers = array_diff($standard_helpers, array('I18N')); 
    sfConfig::set('sf_standard_helpers', $standard_helpers); 

    define('WP_USE_THEMES', true); 
    chdir(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'wordpress'); 
    global $wpdb; 

    ob_start(); 
    require_once('wp-blog-header.php'); 
    $this->blog = ob_get_contents(); 
    if (function_exists('is_feed') && is_feed()) 
    { 
     ob_end_flush(); 
     throw new sfStopException(); 
    } 
    else 
    { 
     ob_end_clean(); 
    } 
    } 
} 
    ?> 

我indexSuccess.php的僅僅是

This is a test 
<?php echo $blog ?> 

我的WP-博客 - 的header.php是

<?php 
/** 
* Loads the WordPress environment and template. 
* 
* @package WordPress 
*/ 

if (!isset($wp_did_header)) { 
    $wp_did_header = true; 

    require_once(dirname(__FILE__) . '/wp-load.php'); 

    // @HACK FABRICE 
    // All variables defined here are considered global by Wordpress 
    $local_global_vars = get_defined_vars(); 
    foreach($local_global_vars as $local_name => $local_value) 
    { 
    $GLOBALS[$local_name] = $local_value; 
    } 
    // Don't create new global variables ourselves, and do not overwrite other global variables, for example $name... 
    unset($local_name, $local_value, $local_global_vars); 
    // @HACK FABRICE 

    wp(); 

    // @HACK Fabrice 
    global $posts; 
    // @HACK Fabrice 

    require_once(ABSPATH . WPINC . '/template-loader.php'); 
} 

這裏的我的問題:

事實上,當我進入頁面時,我什麼也沒有得到。我的Symfony標題,沒有Wordpress內容,沒有任何東西。當我註釋掉「require_once('wp-blog-header.php'');」在actions.class.php中,一切正常,但沒有WordPress的內容。這讓我相信Symfony在包含Wordpress內容的過程中正在死去。這可能如何解決?

回答

3

我已經編寫了關於theodo.fr的有用文章的後續指南,該文章適用於最新版本的WordPress,並且有升級步驟:http://blog.codeclarity.com/2009/12/02/integrating-symfony-and-wordpress/。我相信你的衝突是由Symfony和WordPress定義的esc_js函數。如果你在步驟4中運行我的命令,你應該很好地使用最新版本。希望有所幫助。

+0

太棒了。這真的很好。謝謝您的幫助。 –