4

Hio,

So I have a website which uses the Zend Framework as MVC (www.site.com), and a separate blog set up in wordpress (www.site.com/blog) on the same server, but I want to be able to use Wordpress functions on various pages to pull posts from wordpress.

Currently, the webservers DocumentRoot is /httpdocs/public. public contains a symlink to /httpdocs/blog (I have Options FollowSymlinks on)

All requests are routed through htaccess rules which either redirects it to httpdocs/public/index.php (which then loads Zend stuff) or a regular file/other area not inside the Zend application.

The example code in wordpress is to use the following:

define('WP_USE_THEMES', false);
require(APPLICATION_PATH .'/../blog/wp-blog-header.php');

But... this just tries to redirect me from site.com/page to site.com/page/wp-admin/install.php (which doesn't exist, and so I get a 'this page is redirecting in a way that will never complete' error from firefox, even though site.com/blog is setup and works perfectly fine. For some reason it doesn't seem to recognise that it is (probably because of path issues...)

Does anyone know how I could fix this??

Note: at the moment I just query the wordpress database, but this doesn't work properly because its not formatting the post content properly.

7
  • What does APPLICATION_PATH contain? When is the redirect taking place exactly? Including the header file should never trigger a redirect as far as I know. Commented Aug 22, 2011 at 8:57
  • 1
    Have you created a wp-config.php and loaded it from your bootstrap? If not, WordPress will likely not find your db and try to create one. Commented Aug 22, 2011 at 9:04
  • APPLICATION_PATH is the root path to my website i.e. /var/www/vhosts/.../httpdocs/public/. I can file_get_contents that file as well, so that's fine there (and the paths inside WP are fine when I echo them)... It triggers a header redirect somewhere when it thinks there's no installation I believe?? The redirect takes place just when I load the page. It doesn't actually work, because it SHOULD be site.com/blog/wp-admin/install.php INSTEAD OF site.com/page/wp-admin/install.php ... it's weird! Commented Aug 22, 2011 at 9:09
  • @adlawson there is a wp-config.php inside /httpdocs/blog. I'll try require_once(APPLICATION_PATH . '/../blog/wp-config.php');? I'll give that a try.. NOPE! Didn't work haha, The page isn't redirecting properly. Firefox has detected that the server is redirecting the request for this address in a way that will never complete. Note that now it doesn't redirect to /wp-admin/install.php though... Commented Aug 22, 2011 at 9:10
  • I think you're going to have to dig around this on your own. This is a fairly one-off case, as I can't imagine anyone successfully integrating WordPress into a Zend_Application. Best of luck. Commented Aug 22, 2011 at 9:19

2 Answers 2

3

This is a known issue (Tested with WP 3.2.1 at the time of writing): http://wordpress.org/support/topic/calling-wp-blog-headerphp-from-inside-a-php-function

The solution:

Avoid including the wordpress core inside any class method or function. If it still doesn't work, check the contents of debug_backtrace() to see if you really are on the global scope.

The explanation:

Wordpress sets some variables (direct assignment, does not use $GLOBALS) during initialization. If it's not initialized on the global scope, these variables belong to the current function or method scope. The result is that these variables cannot be accesed by wordpress's core functions, as they rely on the global keyword.

Sign up to request clarification or add additional context in comments.

Comments

3

Benno,

I think I found a work around for this. azkotoki was right, it seems to be an issue of scope when including the wp-blog-header.php or wp-load.php files.

The headers have to be included at a global scope or else Wordpress gets confused and doesn't think its installed and redirects to wp-admin/install.php.

I made my require_once call right along with my Zend application require_once call in index.php of my Zend application's /public/ directory. Unfortunately, this means the Wordpress header will be included even when unnecessary, but at least its working.

...From /public/index.php...

/** Zend_Application */
require_once 'Zend/Application.php';

/** Wordpress Application */
require_once 'wordpress/wp-load.php';

Hope this helps, as it was driving me crazy!

1 Comment

I'm working on a project of somebody else and this doesn't work for me. I get a log stack trace starting like that: Warning: include_once(Requests.php): failed to open stream: No such file or directory in .../library/Zend/Loader.php on line 83 . Any idea why?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.