integrating Wordpress with Symfony

喜你入骨 提交于 2019-11-30 18:41:21

问题


I have a site built with Symfony 1.2. I'm trying to integrate Wordpress 2.8.4 into it to power my blog. I followed the instructions at http://www.theodo.fr/blog/2009/03/integrate-wordpress-into-symfony/, including the 2 steps in the comments at http://www.theodo.fr/blog/2009/03/integrate-wordpress-into-symfony/comment-page-1/#comment-573. My actions.class.php file looks like this:

 <?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();
     }
   }
 }
    ?>

My indexSuccess.php is simply

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

And my wp-blog-header.php is

<?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' );
}

Here's my problem:

As it is, I get nothing when I go to the page. None of my Symfony headers, no Wordpress content, nothing. When I comment out the line "require_once( 'wp-blog-header.php' );" in actions.class.php, everything works fine but there is no Wordpress content. This leads me to believe that that Symfony is dying somewhere in the process of including the Wordpress stuff. How this might be fixed?


回答1:


I've written a follow-up guide to the helpful article on theodo.fr that works with the latest versions of WordPress and has steps for upgrading: http://blog.codeclarity.com/2009/12/02/integrating-symfony-and-wordpress/. I believe your conflict is the esc_js function defined by both Symfony and WordPress. If you run my command in step 4 you should be good to go with the latest version. Hope that helps.




回答2:


I tried for a while, but couldn't get this to work in 2.8.4. I did, however, get just about everything working with Wordpress 2.7.1 using the following links and some tinkering:

Step 1: Description of hacks necessary to make WordPress work inside Symfony.

Step 2: Share user information between Symfony and Wordpress

More code for step 2

Help setting up session database



来源:https://stackoverflow.com/questions/1506096/integrating-wordpress-with-symfony

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!