开发者

Zend Framework and Wordpress Integration

We have an existing Zend Framework site开发者_JAVA技巧 hosted at ourdomain.com and a wordpress blog at blog.ourdomain.com

We want to migrate the blog into the site at ourdomain.com/blog - but I seemed to have googled to the end of the earth and cannot find out how. I have tried various .htaccess stuff, setting up a blog controller and including some wordpress files, etc - but to no avail.

Does anyone have any ideas?

Virtual host setup:

ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/Users/bradyeager/Sites/TWPZend/public"
ServerName twps
ErrorLog "logs/twps-error-log"
CustomLog "logs/twps-access_log" common

Options Indexes FollowSymLinks

AllowOverride All

Order allow,deny
Allow from all


The most efficient and easiest way to accomplish this by modifying your .htaccess file to NOT send anything that starts with /blog to the ZF app -- just pass it through to Wordpress. Wordpress would have to be installed inside your document root, of course, for this to work, exactly how you would normally install it.

An example:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^blog - [NC,L]

RewriteRule ^.*$ index.php [NC,L]

All this nonsense about creating custom controllers, actions and routes in your ZF app, then passing off to Wordpress via your app is absolutely ridiculous. You'd be executing a full dispatch cycle of your application's engine, just to forward off to another app?


I often use this configuration actually , here's what I do:

 /application
 /library
     /Zend 
     /wordpress ( symlink to my wordpress folder )
 /public
     index.php ( i add wordpress & the zend folder to my include path )

Admittedly a bit of a brutal solution , considering all the unnecessary stuff that's included in the process...

Edit:

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    realpath(APPLICATION_PATH . '/../library/wordpress'),
    get_include_path(),
)));

//Get the wordpress environment
define('WP_USE_THEMES', false);
require_once 'wp-blog-header.php';

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



// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV, 
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
            ->run();


One of the best articles about migrating a non-ZF site into ZF is from Chris Abernethy.

Like you, he sets up a special controller for those non-ZF handled script. However, he (eventually) sets up ZF-routes corresponding to those non-ZF pages, rather than playing around with external .htaccess.

Might not apply directly to your case, since your example involves a subdomain while his involves pages on the same domain. But there are some good ideas in there that might be helpful.


See the correct answer provided by Jason. Just make sure your wordpress .htacess file is rewriting to the correct index.php By default, it will rewrite back to the base index.php - which belongs to Zend. My solutions was to change Wordpress' .htaccess RewriteBase to /blog instead of /


I wrote an open source library that might solve your problem called Vulnero that allows you to run your Zend Framework application inside WordPress. Your routes get handled by your app, everything else goes to WordPress. Can even render your views in your WordPress template if you like. Integrates authentication, database connections, all that. Source is on GitHub or you can read the documentation at http://www.vulnero.com/.


For migrating Wordpress into ZF you can use wploader.
This works for me when i use wordpress as multiple site enabled.
You can use all ZF controller objects inside your wordpress files.
You don't need any hack in your wordpress , so you can upgrade or update your wordpress version easily.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜