移植字preSS到Laravel - Json的API和字preSS的API [英] Porting Wordpress to Laravel - Json API vs Wordpress apis

查看:179
本文介绍了移植字preSS到Laravel - Json的API和字preSS的API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我而动从Word preSS我的网站Laravel 4作为网站已经从一个博客搬走了,需要更多的企业和定制功能。

字preSS的博客功能是真棒,我想继续使用Word preSS此功能,让它做它本身最好

对齐

我已经建立了WP-插件来实现所需的定制的基本水平,但是我觉得好像该网站已超越字preSS。我真的需要一个MVC解决方案,并为我的webapp关注的明确分离,而不需要混合使用OOP MVC code。与WP /程序code。

我不介意有2登录 - 字preSS后端和放大器; laravel后端...

显然,我想该网站的博客部分看起来一样的网站的主要组成部分。

我希望通过保持安装的Word preSS在一个单独的文件夹到主应用程序Laravel实现这一目标。

从这里,我有两个选择,从laravel内加载了字preSS和用字preSS API或替代,暴露的JSON API或类似的博客。

这将提供让我创建一​​个Android / IOS应用程序和共享主站点与放大器之间的内容好处;移动设备。

通过字preSS API访问WP

配置/ app.php - 示例

  ...
定义('WP_USE_THEMES',FALSE);
require_once(配置::得到('app.wp_path')'/wp-load.php');
可湿性粉剂();
....

这将使我通过文字preSS API访问的帖子。

通过JSON-API插件访问WP

使用这个插件,我将能够创建一个博客模型,并通过查询卷曲和放话preSS职位; JSON请求。

控制器/ BlogController.php - 示例

 类BlogController扩展BaseController {
    公共$宁静= TRUE;
    公共职能getIndex(){
        $数据['职位'] =博客:: getPosts(1);
        $数据['页'] = 1;        返回查看::让('blog.index') - >在($的数据);
    }
}

型号/ blog.php的 - 示例

 公共静态功能getPosts($页= 1)
{
    //经由卷曲指定URL获取数据
    $ URL =htt​​p://domain.com/api/get_posts/?page=。 $页面;
    $帖=自::卷曲($网址);
    返回$岗位;
}

的问题(S)

在present,我喜欢暴露,因为未来的可扩展性等。此外,字preSS将只在需要时加载的JSON-API的想法。

我也喜欢在我的wp帖子可以访问和Laravel应用程序中显示的清洁和一致的方式。

任何意见/有关下列注意事项?


  1. 应用性能

  2. 安全

  3. ,我还没有考虑什么?

  4. 整合字preSS和放大器的较好的方法; laravel?


解决方案

您应该尽量保持字preSS'博客的功能分开,你的webapp的其余部分。除非有真正的好理由的话preSS API集成到你的web应用(我猜你只想要博客/评论功能?),你将要重复了很多努力。

什么是错有你的博客剥皮看起来像网站的休息,只是简单地安装字preSS到一个独立的子域或只是把它变成你的公共/ 您Laravel应用程序内的文件夹?

如果您需要的JSON API,您既可以创建围绕现有的Word preSS API的应用Laravel的包装(这与Word preSS的每一个版本变得更好)。

正如你所说,字preSS是惊人的与它的博客功能。那么,为什么你想通过创建一个新的接口进行复制呢?这似乎只是中浪费宝贵的时间。

有没有需要包括文字preSS以访问一个API,字preSS附带一个真棒的 XML-RPC API 。文档有时会有点欠缺,但它是什么,有点Googlefu或读取XML服务器的源解决不了!

I am moving my site from Wordpress to Laravel 4 as the site has moved away from being a blog and requires more enterprise and custom functionality.

The blogging capabilities of Wordpress are Awesome, and I would like to continue using Wordpress for this functionality, letting it do what it does best natively.

Justification

I have built wp-plugins to achieve basic levels of required customisations, however I feel as though the site has outgrown wordpress. I really need an MVC solution and a clear separation of concerns for my webapp, without the need to intermix OOP MVC code with wp/procedural code.

I don't mind having 2 logins - wordpress backend & laravel backend...

Obviously, I would like the blog part of the site to look the same as the main part of the site.

I hope to achieve this by keeping installation of Wordpress in a separate folder to the main application Laravel.

From here, I have two options, load up wordpress from within laravel and use the wordpress api or alternatively, expose a json-api or similar of the blog.

This will provide added benefit of allowing me to create an Android / IOS app and share content between main site & mobile devices.

Access WP via wordpress api

config/app.php - Example

...
define('WP_USE_THEMES', false);
require_once(Config::get('app.wp_path') . '/wp-load.php');
wp();
....

this will enable me to access the posts via wordpress api.

Access WP via json-api plugin

Using this plugin, I will be able to create a blog model and query the wordpress posts via curl & json requests.

controllers/BlogController.php - Example

class BlogController extends BaseController {
    public $restful = true;
    public function getIndex() {
        $data['posts'] = Blog::getPosts(1);
        $data['page'] = 1;

        return View::make('blog.index')->with($data);
    }
}

models/Blog.php - Example

public static function getPosts($page = 1)
{
    // get data from specified url via curl
    $url = "http://domain.com/api/get_posts/?page=" . $page;
    $posts = self::curl($url);   
    return $posts;
}  

The Question(s)

At present, I like the idea of exposing a json-api because of future extensibility etc. Furthermore, wordpress will only be loaded when required.

I also like the clean and consistent way in which my wp posts can be accessed and displayed within Laravel application.

Any comments / considerations in relation to the following?

  1. Application Performance
  2. Security
  3. Anything that I haven't considered?
  4. Better way of integrating wordpress & laravel?

解决方案

You should try to keep WordPress' blogging functionality separate to the rest of your webapp. Unless there is really good justification for integrating the WordPress API into your webapp (I am guessing you only want the blog/comment functionality?) you are going to be duplicating a lot of effort.

What is wrong with having your blog skinned to look like the rest of the website, and simply just installing WordPress into a separate subdomain or just putting it into your public/ folder inside your Laravel app?

If you need a json-api, you could either create a wrapper in your Laravel app around the existing WordPress API (which gets better with every release of WordPress).

As you said, WordPress is amazing with it's blogging capabilities. So why are you trying to replicate them by creating a new interface? That just seems like a waste of valuable time.

There is no need to include WordPress to get access to an API, WordPress ships with an awesome XML-RPC API. The documentation can sometimes be a little lacking, but it is nothing that a little Googlefu or reading the source for the XML server can't solve!

这篇关于移植字preSS到Laravel - Json的API和字preSS的API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆