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

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

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

#1 User is offline   acorncom 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 25-February 11
  • Location:CO, USA

Posted 25 April 2012 - 09:35 AM

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.
0

#2 User is offline   acorncom 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 25-February 11
  • Location:CO, USA

Posted 25 April 2012 - 09:46 AM

Quote

So far, I really like this approach. I haven't seen a significant degradation of performance, and that makes me very happy (probably because Yii is so lean and mean).

What I have noticed is that the error logs are recording that my permalinks won't resolve, even though the pages ultimately display:

2012/04/24 01:23:31 [error] [exception.CHttpException.404] exception
'CHttpException' with message 'Unable to resolve the request
"sidebar-items/contact-sidebar".' in
/home/lfs12/yii_framework/web/CWebApplication.php:280
Stack trace:
#0 /home/lfs12/yii_framework/web/CWebApplication.php(135):
CWebApplication->runController('sidebar-items/c...')
#1 /home/lfs12/yii_framework/base/CApplication.php(162):
CWebApplication->processRequest()
#2 /home/lfs12/slowmoneycolorado.org/index.php(21):
CApplication->run()
#3 {main}
REQUEST_URI=/sidebar-items/contact-sidebar/
HTTP_REFERER=http://slowmoneycolorado.org/main-menu/blog/
Any idea what's up with that and how we could get it to not register errors (or go through the added effort of generating an error before displaying)?


I also noticed that it was looking for the Yii stylesheets, so I created aliases to them from the WP Theme folder.


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

'urlManager'=>array(
        'rules'=>array(
                ....
                '*'=>'wpFallback/index',
        ),
),
// Error handler
'errorHandler'=>array(
        // use 'site/error' action to display errors
        'errorAction'=>'wpFallback/index',
),


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.
0

#3 User is offline   Ocean Wind 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 14-September 10
  • Location:Denver, Colorado, USA

Posted 25 April 2012 - 01:10 PM

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...?
0

#4 User is offline   acorncom 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 25-February 11
  • Location:CO, USA

Posted 25 April 2012 - 01:15 PM

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).
0

#5 User is offline   Ocean Wind 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 14-September 10
  • Location:Denver, Colorado, USA

Posted 25 April 2012 - 02:34 PM

View Postfr0d0z, on 25 April 2012 - 01:15 PM, said:

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.
0

#6 User is offline   acorncom 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 25-February 11
  • Location:CO, USA

Posted 15 July 2012 - 07:21 PM

I've updated the wiki article with an approach that should handle the 404 errors mentioned by OceanWind above:
http://www.yiiframew...ter-controller/

@OceanWind: interested in whether that works for you.
0

#7 User is offline   Ocean Wind 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 14-September 10
  • Location:Denver, Colorado, USA

Posted 07 August 2012 - 08:18 PM

View Postfr0d0z, on 15 July 2012 - 07:21 PM, said:

@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:

  • 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:



Quote

Create your controller view
Create a view/wpFallback/index.php file for your wpFallback controller, which loads WordPress up all the way.


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).




Bill
0

#8 User is offline   acorncom 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 25-February 11
  • Location:CO, USA

Posted 10 August 2012 - 08:16 PM

View PostOcean Wind, on 07 August 2012 - 08:18 PM, said:

  • 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?


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.

View PostOcean Wind, on 07 August 2012 - 08:18 PM, said:

At one point you say:
Did you mean to say view/wp/index.php here?


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

View PostOcean Wind, on 07 August 2012 - 08:18 PM, said:

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).


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

#9 User is offline   kiennguyen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 28-August 11

Posted 28 August 2012 - 06:37 AM

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.
0

#10 User is offline   cnick79 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 24-June 12

Posted 30 August 2012 - 08:45 AM

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?
0

#11 User is offline   acorncom 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 25-February 11
  • Location:CO, USA

Posted 30 August 2012 - 05:22 PM

View Postkiennguyen, on 28 August 2012 - 06:37 AM, said:

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.


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
0

#12 User is offline   acorncom 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 25-February 11
  • Location:CO, USA

Posted 30 August 2012 - 05:24 PM

View Postcnick79, on 30 August 2012 - 08:45 AM, said:

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?


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.
0

#13 User is offline   cnick79 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 24-June 12

Posted 31 August 2012 - 08:05 AM

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.
0

#14 User is offline   acorncom 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 25-February 11
  • Location:CO, USA

Posted 04 September 2012 - 09:03 AM

View Postcnick79, on 31 August 2012 - 08:05 AM, said:

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.yiiframew...out-the-details Might be useful.

Good luck and let us know how it goes!
0

#15 User is offline   cnick79 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 24-June 12

Posted 05 September 2012 - 08:01 AM

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?
0

#16 User is offline   davidgraybeard 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 13-December 12

Posted 13 December 2012 - 04:30 PM

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.


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

This post has been edited by davidgraybeard: 13 December 2012 - 07:37 PM

0

#17 User is offline   MichaelG 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 19-October 10
  • Location:Roseville, CA

Posted 13 February 2013 - 06:17 PM

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
http://www.yiiframew...post__p__165996

(this thread, 8th item)

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

#18 User is offline   acorncom 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 25-February 11
  • Location:CO, USA

Posted 14 February 2013 - 07:52 PM

View PostMichaelG, on 13 February 2013 - 06:17 PM, said:

EDIT -> #1 solved... rereading this thread (more) carefully revealed the answer here
http://www.yiiframew...post__p__165996

(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 :-)
0

#19 User is offline   dualsun 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 22-March 13

Posted 25 March 2013 - 08:43 PM

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
  • 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.
0

#20 User is offline   acorncom 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 25-February 11
  • Location:CO, USA

Posted 26 March 2013 - 10:28 AM

View Postdualsun, on 25 March 2013 - 08:43 PM, said:

I have a system coming that is YII and would like to ask if I can have
  • 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. :-) 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.
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users