【问题标题】:Drupal: - Field Info API as RESTDrupal: - 作为 REST 的字段信息 API
【发布时间】:2015-11-23 09:23:54
【问题描述】:

我们想获得该字段的标签。

根据上一个问题:How do I get a field label by the field name?

但我需要通过 Drupal 的 REST API 来获取。

任何人都可以建议将 Field API 用作 REST 的方法

【问题讨论】:

    标签: rest drupal-7 drupal-fields drupal-field-api


    【解决方案1】:

    我可以通过 REST API 获取值。

    /**
     *  Implements hook_menu().
     */
    function sample_menu() {
        $items['api/sample'] = array(
            'title' => 'Sample REST API',
            'page callback' => 'sample_api',
            'access callback' => true
        )
    }
    
    /**
     * callback function for /api/sample
     */
    function sample_api() {
       $entityBody = file_get_contents('php://input'); // if you want to get post data
       drupal_add_http_header('Content-Type', 'application/json');
    
       // set values from Fields and so on
    
       drupal_json_output(array("output" => 'this is rest api sample module output.', 'id' => 12345));
       drupal_exit();
    }
    

    【讨论】:

    • @Banng 如果你解决了这个问题,我希望你关闭这个问题。
    猜你喜欢
    • 2019-08-03
    • 2010-11-02
    • 2019-09-13
    • 1970-01-01
    • 2018-11-08
    • 2016-08-21
    • 1970-01-01
    • 2012-03-23
    • 2016-03-24
    相关资源
    最近更新 更多