将 WordPress 集成到 Kohana 与将 Kohana 集成到 Wordpress
我开始在一个主要是博客的个人网站上工作,其中有一个用于各种技术项目的部分,小到自定义照片库,大到餐厅评论网络应用程序。之前没有使用过 WordPress 或 Kohana,我很好奇将 WP 集成到 Kohana(或任何其他框架)中的优势是什么,考虑到这种情况,反之亦然。
我在网上看到过一些提到的内容,但没有明确的帖子比较这两种方法,所以我希望其他人可以在这里参与:)
I'm starting work on a personal site that's primarily a blog, with a section for various tech projects as small as a custom photo gallery to as large as a restaurant-review web-app. Not having worked with WordPress or Kohana before, I'm curious what the advantages are of integrating WP into Kohana (or any other framework, for that matter), and vice versa, given this situation.
I've seen bits of this mentioned here and there online, but no definite post comparing the two approaches, so I'm hoping others can pitch in here :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我以前没有使用过这个,但是 kerkness 已经为它编写了一个插件:https://github。 com/kerkness/kohana-for-wordpress 然而,它已经很旧了,所以你可能想寻找更新的东西。
I've not used this before, but kerkness has written a plugin for it: https://github.com/kerkness/kohana-for-wordpress However, it is quite old so you might want to look for something newer.
人们常常寻求将 Wordpress 与框架(Kohana、CodeIgniter、Zend 等)集成,但没有解决第一个也是最重要的问题:您希望在功能级别将两者集成到什么程度?
一般来说,有两种高级方法可以集成任意两个 PHP 产品:
1) 在 PHP 代码中,将两个产品中的库、引导脚本等包含到一个或多个脚本中(创建一个 “杂交种”)。
作为开发人员,您应该能够在最终的混合产品中使用这两种产品的大部分功能。例如,对于 Wordpress 和 Kohana,完整的结果将允许您使用 Kohana 功能(例如,路由、身份验证等)和 Wordpress 功能(例如,获取帖子内容、作者等)。
这种方法的困难在于竞争 API 和代码期望,这可能会使混合行为出现意外,例如,
尝试此过程时我想要解决的第一个问题是路由,我是否要从 Kohana 内部将帖子、附件等的获取委托给 Wordpress,或者我是否必须在 Kohana 的路由器、控制器之间构建一个接口和Wordpress?
虽然此选项很有吸引力,因为您可以访问这两个产品 API,但您必须准备好对应用程序行为进行重大更改,以便允许这两个产品和平共存。如果这听起来像是一项繁重的工作,那是因为它确实是一项繁重的工作!
2) 使用网络服务器智能地将请求路由到不同的产品。
从您的问题来看,您似乎希望网站的某些部分加载不一定需要上述集成级别的 Web 应用程序(例如,您真的需要在评论应用程序或照片库中获取 Wordpress API 吗? )。如果您只是寻找一种使用相同应用程序域加载两个应用程序的方法,那么此选项会更适合,因为您不需要在两者之间执行太多(如果有)集成。
假设您使用的是 nginx 或 Apache Httpd 等网络服务器,您应该能够为网站的不同部分创建不同应用程序的别名。
例如,
http://myblog.nonex/ - 指向 Wordpress 安装,后者管理默认站点(显示页面、博客文章等均来自 Wordpress)。
http://myblog.nonex/apps/review - 指向评论应用程序,即 Kohana 安装。
http://myblog.nonex/apps/gallery - 指向图库应用程序,该应用程序(具有适当的模块化)可以与审查应用程序一起存在于同一 Kohana 安装中。
由于您仍处于规划和开发阶段,我建议首先选择选项 2) - 构建原型,确定您绝对需要 Kohana 中的 Wordpress 功能的任何区域(例如,评论或图库应用程序是否需要使用Wordpress 用户凭据?)并考虑在创建完整的混合之前执行最小的集成。
Integrating Wordpress with a framework (be it Kohana, CodeIgniter, Zend, etc.) is often sought without addressing the first and most important question: How far do you want to integrate the two at a feature level?
Broadly speaking, there are two high-level approaches to integrating any two PHP products:
1) In the PHP code, include the libraries, bootstrap scripts, etc. from both products into a script or scripts (creating a "hybrid").
As a developer you should be able to use most of the features from both products in the resulting hybrid. For example, in the case of Wordpress and Kohana, the complete result would allow you to use Kohana features (e.g., routing, auth, etc.) and Wordpress features (e.g., fetching post contents, authors, etc.).
The difficulty with this approach is competing APIs and code expectations that might make the hybrid behave unexpectedly, e.g.,
The first issue I would want to resolve when attempting this process is the routing, am I going to delegate fetching of posts, attachments, etc. to Wordpress from within Kohana, or am I going to have to build an interface between Kohana's router, controllers and Wordpress?
While this option is appealing because you can access both product APIs, you must be prepared to make significant changes to the application behaviour in order to allow both products to co-exist peacefully. If this sounds like a lot of work, it is because it is a lot of work!
2) Use the webserver to intelligently route requests to different products.
From your question, it sounds like you want parts of the website to load web applications that don't necessarily need the level of integration indicated above (e.g., would you really need to get Wordpress API in the review application, or the photo gallery?). If you are just looking for a way to load two applications using the same application domain, this option would be better suited because you don't need to perform much (if any) integration between the two.
Assuming you are using a webserver like nginx or Apache Httpd, you should be able to create aliases for different parts of the site to different applications.
e.g.,
http://myblog.nonex/ - points to the Wordpress installation, which in turn manages the default site (shows pages, blog posts, etc. all from Wordpress).
http://myblog.nonex/apps/review - points to the review application, which is the Kohana installation.
http://myblog.nonex/apps/gallery - points to the gallery application, which (with proper modularisation) could exist alongside the review application in the same Kohana installation.
Since you are still in the planning and development stage, I would recommend going for option 2) first - build a prototype, identify any areas where you absolutely need features from Wordpress in Kohana (e.g., would either the review or gallery application need to use the Wordpress user credentials?) and look at performing a minimal integration before creating a full hybrid.