0
votes

I'm trying to integrate Wordpress in CakePHP 2.6.1 to use it as a CMS for my end users. I'm including the required file to access wordpress functions: wp-blog-header.php.

As CakePHP only allows to include files located inside CakePHP I placed the wordpress intallation inside app/Vendor/wordpress and now I'm trying to import the necesary file in my AppController in this way:

App::import('Vendor', 'wordpress'.DS.'wp-blog-header');

But it seems there's some functions conflict as I'm getting this error from CakePHP:

Error: Cannot redeclare __() (previously declared in /home/todopeta/alvarotrigo/pruebas/cakephp/lib/Cake/basics.php:581)
File: /home/todopeta/alvarotrigo/pruebas/cakephp/app/Vendor/wordpress/wp-includes/l10n.php
Line: 163

Has anybody integrated wordpress in CakePHP before?

What's the way to go for it?

I've seen it seems to be possible with other PHP MVC frameworksk such as Laravel. Is CakePHP more restrictive in this respect?

2
So you are decorating your cake with cowpat, that doesn't sound very tasty... I'd advise not trying to mix the two, it's a receipe for a catastrophe, if you really need to use WP for whatever reason, run it separated from your CakePHP app. google.com/search?q=wordpress+and+cakephp - ndm
@ndm but CakePHP doesn't allow to include files from outside itself. Am I wrong? - Alvaro
It's php, you can include as much as you want. The issue is that you probably will have to have include tons of files and do some bootstrapping or initialization for the WP scripts as well which then ends up in a pretty fugly piece of code. - floriank

2 Answers

1
votes

Access the WP data by creating a WP plugin for CakePHP and add a model for each of the WP tables and read the data via CakePHP.

Your linked article does the same but it uses the WP_Query class and further down Corcel which seems to be a mix between the Eloquent ORM and WP. I would not go that path and use the CakePHP ORM.

I can guarantee you that everything else is going to become a pain in the rear thanks to the fugly WP code and architecture.

If you try to use the WP code inside CakePHP like you've tried this will become super painful, time consuming and probably never work right without some really really fugly code.

If you need only parts from WP consider creating a WP plugin and embedd the WP content via an iframe in your page. AFAIK WP got a json API as well these days, you could try to read the data via that API as well.

1
votes

You're going to have a nightmare and end up with a massive mess of code with this approach.

Instead, why not try and use a CakePHP CMS system, for example:

https://croogo.org/