Integrate Wordpress CMS in CakePHP

让人想犯罪 __ 提交于 2019-12-13 05:43:22

问题


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?


回答1:


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.




回答2:


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/



来源:https://stackoverflow.com/questions/28398788/integrate-wordpress-cms-in-cakephp

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