Hello. I am Denis Melsky. I work PHP Developer in DataArt. My professional interests are Web Development and Linux. Today I would like to talk to you about "hedgehog crossing with a snake."

Intro
At first glance it may seem like madness and, in some way, an architectural crutch. But, if you look at it from the other side, this is one of the options for getting out of the frequently encountered deadlock: the customer wants WordPress and does not recognize anything else. Most likely, he heard something like this, googled, saw, coder John (well, or Vasya), advised the neighbor of the guru.
And programmers flatly refuse to pull on the blog engine, with, to put it mildly, not the best architecture, functionality, for example, an online store, forum, and in addition - REST API for partners of this store, and on top - another pack of kronas with business logic.
')
Let's set the task to find such a way out to satisfy all the participants in the problem, and to start our product and work normally.
One of the options that I found while conducting research on this topic is the crossover of WordPress and Yii.
Let the party begin
Well, let's try to master some of this in the code.
Let's start by downloading the Yii framework. I think the composer for such experiments is a bust - because of the customization of the paths and the architecture of the entire assembly, we will have more opportunities for experiments without a composer, i.e., we calmly download from our
own site .
We make the same simple manipulation with
WP .
Further we arm with auxiliary manuals:
TimeTwoWe go on the first manual, to which I want to add a few comments and comments.
Installing WP we place everything in this architecture:

First, consider the key lines of our index.php.
define('WP_USE_THEMES', true); $wp_did_header = true; require_once('wordpress/wp-load.php');
Here we can observe the beginning of connecting WP into the overall picture of what is happening.
We create the Exception Handler class, the essence of which on the 404 exception yii framework is to transfer power to WP.
Making default .htaccess for Yii, which allows you to make beautiful URLs.
RewriteEngine on
Register in the Yii config 'showScriptName' => false and uncomment the default rules for stock delivery.
Next, on the above manual create a WpController and View to it.
Another interesting point that cannot be ignored: in the wordpress configs at the DB level there is a setting in the `wp_options`—“ siteurl ”table, it needs to be changed to
yourdomain / wordpress . This can also be changed in the WP admin panel.
Settings -> General -> WordPress Address (URL).
I can not fail to mention an interesting point: in the main layout Yii we place the structure of the inside of our theme from WP.

We are already close to victory: we connect gii (who can’t read it
here ).
In gii, we can both create a CRUD model and get what we really want at the output - the crossed code Yii and WP.

It's alive!
On this screen we can see a beautiful CRUD from Yii using a CGridView.
For authorization we will try this
method everywhere.
At the root, create a wordpress folder and transfer the insides of the WP itself.
According to the results of my search, we get the following conclusions:
- Frontend WP can be passed through Yii very much with the adjustment of the theme and as a result, we can get custom modules on Yii, which will live harmoniously with WP. In addition, it is possible to synchronize users from WP to Yii.
- Backend WP did not work out harmoniously with Yii, that is, a general admin for standard WP modules and custom Yii modules is not the best implementation. This is due to the fact that in backend-e WP a very non-standard architecture is not very suitable for integration. But these are the results of my research, which do not pretend to be the ultimate truth.
- As a result, we can develop an application where the frontend WP will harmoniously combine with the custom modules Yii. In the backend WP, we can develop custom plugins and, as one of the implementation options, load Yii. And even, I’m not afraid of this option, to render some Yii modules via an iframe inside a WP plugin.
PS I want to wish everyone the right choice of tools for solving a certain range of tasks for which they were created, but also not to lose the excitement of experimentation
PPS A few links on the topic:
Examples of similar approaches for the implementation of ideas in some also slightly different customizations are used yii.
www.yiiframework.com/wiki/382/integrating-wordpress-and-yii-working-out-the-detailswww.yiiframework.com/wiki/322/integrating-wordpress-and-yii-still-another-approach-using-yii-as-the-router-controllerwww.yiiframework.com/wiki/213/integrating-wordpress-and-yii-yet-another-approachwww.yiiframework.com/wiki/202/integrating-yii-with-wordpresswww.yiiframework.com/wiki/144/run-an-yii-application-inside-an-wordpress-page