【问题标题】:Is there a cakephp component to create full APIs?是否有用于创建完整 API 的 cakephp 组件?
【发布时间】:2014-08-01 05:46:38
【问题描述】:

我正在尝试为多个模型构建一个 RESTful api。

我发现了这个:

class RecipesController extends AppController {

public $components = array('RequestHandler');

public function index() {
    $recipes = $this->Recipe->find('all');
    $this->set(array(
        'recipes' => $recipes,
        '_serialize' => array('recipes')
    ));
}

public function view($id) {
    $recipe = $this->Recipe->findById($id);
    $this->set(array(
        'recipe' => $recipe,
        '_serialize' => array('recipe')
    ));
}

public function edit($id) {
    $this->Recipe->id = $id;
    if ($this->Recipe->save($this->request->data)) {
        $message = 'Saved';
    } else {
        $message = 'Error';
    }
    $this->set(array(
        'message' => $message,
        '_serialize' => array('message')
    ));
}

public function delete($id) {
    if ($this->Recipe->delete($id)) {
        $message = 'Deleted';
    } else {
        $message = 'Error';
    }
    $this->set(array(
        'message' => $message,
        '_serialize' => array('message')
    ));
}
}

但我试图避免在我需要创建的每个控制器中重复所有这些方法。我一直在寻找一个组件来执行我可以包含在每个控制器中的所有 CRUD 操作。

1) 这样的组件是否存在? 2)当我应该为每个模型复制这个基本控制器时,我是否过度使用了这个东西?

【问题讨论】:

    标签: json cakephp cakephp-2.0 json-api


    【解决方案1】:

    我认为你最好的选择是:

    https://github.com/FriendsOfCake/crud

    “CakePHP 应用程序开发在类固醇上 - 快速原型设计/脚手架和生产就绪代码 - JSON API 等”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-21
      • 1970-01-01
      • 1970-01-01
      • 2021-12-23
      相关资源
      最近更新 更多