Make WordPress Core

Opened 16 years ago

Closed 16 years ago

#11066 closed defect (bug) (duplicate)

Can't integrate Wordpress 2.8.5 with CodeIgniter

Reported by: gthorne's profile gthorne Owned by: westi's profile westi
Milestone: Priority: normal
Severity: normal Version: 2.8.5
Component: General Keywords: reporter-feedback
Focuses: Cc:

Description

I haven't tried to embed copies of Wordpress before 2.8.5, but I assume previous versions could be 'embedded' using the instructions on this page: http://codex.wordpress.org/Integrating_Wordpress_with_Your_Website

However, I am now trying to use these instructions to embed into a CodeIgniter project, and am getting an error. The error says: Fatal error: Call to undefined method stdClass::set_prefix() in wp-settings.php on line 270 Checking the forums, it seems a number of other users are getting the same error as well. So far, nobody has come up with a workable resolution. There are a number of threads either dealing with this issue directly:
http://wordpress.org/support/topic/326677
http://wordpress.org/support/topic/322313
http://wordpress.org/support/topic/280905
http://wordpress.org/support/topic/322645
http://wordpress.org/support/topic/309873
http://wordpress.org/support/topic/285890

Change History (11)

#1 @scribu
16 years ago

  • Summary changed from Can't embed Wordpress 2.8.5 to Can't integrate Wordpress 2.8.5 with CodeIgniter

#2 @scribu
16 years ago

  • Version set to 2.8.5

#3 @gthorne
16 years ago

I saw that the title was changed to 'Can't Integrate Wordpress 2.8.5 with CodeIgniter'. While technically correct, if you check the referenced forum posts, this is also an issue with CakePHP, Zend MVC, and practically any simple PHP script. It's not an issue with 'CodeIgniter', per se, but is rather a bigger problem than that.

#4 @westi
16 years ago

  • Owner set to westi
  • Status changed from new to accepted

#5 @westi
16 years ago

  • Keywords reporter-feedback added; embed integrate wordpress removed

Ok I have had a look at this and cannot reproduce using a simple test script here.

Could you provide an example simple script which doesn't work for you?

Here is what I tried:

<?php
require('/Applications/MAMP/htdocs/wp-2.8.4/wp-blog-header.php');
$posts = get_posts('numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) : the_post(); ?>
<?php the_date(); echo "<br />"; ?>
<?php the_title(); ?>    
<?php the_excerpt(); ?> 
<?php
endforeach;
?>

The implication from the error message is that the $wpdb global is not an instance of the WPDB class.

Maybe some other code is setting this before WordPress tries?

#6 @dd32
16 years ago

Westi: Try again with the require() inside a function..

Ie.

function require_wp() {
require('/Applications/MAMP/htdocs/wp-2.8.4/wp-blog-header.php');
}

While it definitely would not be a regression, I can see that this could cause that error due to wp-settings expecting to have global scope rather than local scope.

#7 @westi
16 years ago

Thanks - Thats what I get for following the codex example to test :-)

That would break a lot of stuff though including WP in inside a function.

#8 @dd32
16 years ago

That would break a lot of stuff though including WP in inside a function.

I agree.. But i can see some people doing exactly that, And it should provide that exact error message :)

#9 @gthorne
16 years ago

This makes sense. I can't find it now, but another forum post talked about it working with global scope. In my case, I was trying to embed it in either a library (by including it in the class constructor), or inside of a helper (which would be inside of a PHP function).

#10 @Denis-de-Bernardy
16 years ago

  • Milestone changed from Unassigned to 3.0

#11 @Denis-de-Bernardy
16 years ago

  • Milestone 3.0 deleted
  • Resolution set to duplicate
  • Status changed from accepted to closed

Closing as dup of #11549

Note: See TracTickets for help on using tickets.