Discussion off the wiki article "Integrating Wordpress and Yii: still another approach, using Yii as the router/controller"

This forum post is setup to make discussing of the wiki article on integrating WordPress and Yii easier.

Let’s keep the discussion here and use the comments area of the wiki for edits / improvements to the article.

I think you’re seeing this because of these lines in the config file:







// Error handler


        // use 'site/error' action to display errors



Specifically, we’ve set the error handler to point to WordPress. All our rules fall through (I don’t think the * sends all other requests to WordPress as I’d hoped) and so WordPress ends up handling the call, but Yii thought it was an error, so under the hood it’s generating a 404 (and it might even send a 404 header).

So I think we need a better approach to the way we’re handling rules. We’d either need to come up with a better rule to send everything to WordPress or create a custom url manager.

If you do end up figuring it out, would you let me know? I’d love to update the wiki article to make it better.

I wonder if there’s some way to tie into WordPress’s permalink rules and pass them through.

The WP urlManager rules in the .htaccess file are similar to the Yii urlManager rules, and not very complicated. What if we mirrored these in the urlManager and somehow passed them through to your wpFallback controller…?

The permalink tie-in would probably work, but might be a bit of a headache to figure out.

The .htaccess rules for Wordpress have essentially been replaced by using the Yii .htaccess rules, so I don’t think that would get us very much. You could map all WordPress urls to WordPress with the Yii urlManager, but that then means that you don’t have the flexibility to add new permalinks / pages inside of WordPress without having to tinker with Yii (and that was one of the things I’d hoped to avoid).

Agreed. Whatever it is needs to be automated and able to accommodate updates without adding an extra step.

For me the big thing is not having Yii generate an error. I’m not an expert in htaccess code matching, but perhaps we need to generate some kind of hybrid that would work for both of them so Yii doesn’t generate a failure.

In the end, one of them is going to be processed first, and therefore its contents will become restricted words for the other. The best way to deal with this may be to ensure that all Yii routing begins with a constant, such as /yii/. We could add this to the yii routing commands, filtering those requests to yii. This might stop the errors, since Yii would stop trying to interpret the WordPress permalink calls.

I’ve updated the wiki article with an approach that should handle the 404 errors mentioned by OceanWind above:


@OceanWind: interested in whether that works for you.

I’ve finally found a chance (and need) to review your updates. I have a few editorial suggestions:

[list=1][]At the point in the new instructions where you’re supposed to be loading a WordPress page, I’m still seeing the Yii implementation. I’m able to get the WP site to load at http://domain.com/wp, but not at http://domain.com. How is going to the base URL forwarded to the wordpress implementation?[]At one point you say:[/list]

Did you mean to say view/wp/index.php here?

I appreciate the time you’re putting into this. It’s much better than the yii-bridge plugin (although that has its uses as well).


If you take a look at the instructions here again, you probably don’t have it set up right. You need to tell Wordpress that the Wordpress path is http://domain.com so that Wordpress directs all its traffic toward your Yii entry script. Yii then acts as a glorified wp/index.php entry script.

Yes, I did. That was a left over from the former set of instructions. I’ve just updated the article.

Good to know about the yii-bridge plugin, I was wondering if I should be using that instead. :slight_smile:

Hi, how can I change wordpress backend url?

Currently, I can only access using yiitest/wordpress/wp-admin. How do I change it to yiitest/wp-admin? I’ve tried using yii urlmanager in config but it doesn’t work.

I like the idea of being able to use WP as a CMS and Yii as an app. I have a Yii Member app that allows people who signed up to create some schedules and do other tasks. I was thinking about using WordPress as my CMS integrated with aMember as the membership script to handle login/signups and other member profile modifications, and Yii as the app to allow the member to perform tasks.

I’m trying to decide if I should use Yii as a wp-plugin or install Yii infront of WP using this method. Any thoughts, suggestions?

Not sure, I haven’t tried that. You might need to use a .htaccess rewrite rule in order to do that, because you have to actually run the wp-admin/index.php script in order to do things. Let us know if you get it and I can update the article

Going with the Yii in front of WP method may give you more flexibility down the road. The hardest part either way will be integrating your Wordpress login system with Yii. You’ll need to wrap CWebUser / CUserIdentity around the Wordpress user object somehow. If you get it, do let us know, as that’d be a really handy thing to add to the wiki article.

As an added curveball I plan on using aMember as my member management system. aMember has WordPress integration built into it’s core so I’m hoping this will go painless :-X When using WordPress and aMember, all WordPress registration is disabled because all login and logout is handled by aMember. aMember also controls what content members can access.

I already integrated aMember and Yii. aMember has their own am_user table and I have my yii_user table. By creating an aMember plugin any inserts into am_user will insert into yii_user.

To get around the authorization access I have a base controller class that all of my yii app controllers extend. In this base controller I have a use a custom Filter which has a preFilter to check if a user is logged into aMember, then I check if Yii::app()->user->isGuest and if they are, I log them in using my UserIdentity class. The UserIdentity->authorize() function checks the yii_user and if it’s valid, I run Yii::app()->user->login($identity). If anything fails, I redirect the guest to a login page. It’s a work in progress and I still need to add more security checks, but the preFilter class should be enough. If you weren’t using aMember, I would guess you could take a similar approach to integrate yii and WP.

Since I’m already integrated with aMember, I would hope sticking Yii infront of WP or inside of it will be carefree. I’m learning towards inserting my Yii app as a WordPress webpage using the yii-bridge plugin. My thought is this, if WP is on my main site, I can create a mysite.com/member/ page and using the yii-bridge shortcode I can set my Yii app to run from this page, (ie: mysite.com/member/index.php?controller/action). I would set aMember to block access to mysite.com/member/. aMember would make sure anyone trying to access this section is logged in. My yii app controller filter will check if somebody trying to access an app page is logged into aMember (this might be redundant since aMember should handle this) and if they are, then I log them into my app if needed.

My concern is getting Yii, WP, and aMember to all play nice if installing Yii infront of WP. I think it’ll work both ways? I do agree installing yii infront of WP provides more flexibility down the road. It’s the future unknown if I’ll ever need it.

Understood. That’s sounding a tad complicated. I think it’d work with Yii in front, but the bridge might be worth looking into as well. Per OceanWind, the bridge doesn’t work as smoothly, but I haven’t done much more than install it and poke around a little. There was also an article with some additional pointers posted this weekend on the Yii-in-front idea: http://www.yiiframework.com/wiki/382/integrating-wordpress-and-yii-working-out-the-details Might be useful.

Good luck and let us know how it goes!

I still need to iron out my access Filter that ties amember and Yii. Once I feel confident that is working as expected I am going to see how things work using yii-bridge first. Are there any problems using yii-bridge I should be aware of? How about using Yii in front of WP?

This is great! Just what I was looking for to combine a CMS with the MVC based extensibility of Yii.

I followed the steps carefully, but I must still be missing one thing. I can go to harvestation.com/wp/?p=1#comment-1 just fine, but I can’t leave out the /wp.

There are two things I’m not sure I understood properly:


[*]There is a creation of view/wp/index.php. Was this supposed to be views/wp/index.php in the protected folder, or is the view folder somewhere else?

[*]As per the subsequent “Working out the Details” article I added: ‘wp_themes’=>‘webroot.wp.wp-content.themes’, but I wasn’t sure if webroot is literal or should be replaced with either a URL or file path.


[color="#FF0000"]— RESOLVED —[/color]

I figured out what the problem was. I hadn’t set permalinks up in WordPress. Once that was done things worked fine.

Seems like it’s working pretty well so far. Thanks for writing it up.

I have a couple of questions, so far

  1. Since Wordpress is installed under the <domain>\wordpress\ I’d like the \sample-page for example to be <domain>\sample-page versus <domain>\wordpress\sample-page If this were strictly Yii, I’d mess with the routing, but I thought I’d see if anyone else had this problem and solved it and is willing to share what they did.

  2. and maybe this will go away if #1 is resolved… but my main site home page is loading the views\site\index.php (wrapped in Wordpress header nicely), but I’d like it to load the <domain>\wordpress\ default page instead. If I remove the actionIndex from the site controller, I thought maybe it would then failover to the <domain>\wordpress\ page, but that only works if the permalinks is set to the default.

I’ll post up solutions if I resolve prior to anyone responding.

thanks for your efforts and time.

EDIT -> #1 solved… rereading this thread (more) carefully revealed the answer here


(this thread, 8th item)

#2 item resolved by removing site controller’s actionIndex after resolving the first item

Glad to hear it, I was just getting on to work on answering your questions :slight_smile:

you guys amaze me, I’m a system designer, not a programmer so it takes me a while to read through and understand what the code you write is doing and if it relates to what I need to do. But I can’t find the answer so I’d like to ask…

I have a system coming that is YII and would like to ask if I can have [list=1]

[*]a wordpress front end that advertises my system, and has a menu link (login) for user to click,

[*]which takes them to my YII system login screen.


The WP and YII are not integrated, there is no info shared between them, just the WP has a link to take the user to the YII login screen. On login then the YII system takes over.

I’m sorry for this silly question but I cannot find the answer anywhere, I’d like to ask if you think this will work easily or if a lot of things have to be done so it can work.

The short answer is absolutely. :slight_smile: And you should be able to integrate Yii/Wordpress logins if needed/desired as well. If you end up needing help integrating things, let me know, I also do this type of stuff freelance.