2

I'm working with the module "services" everything's ok with a get request, note that i've create my own custom resource with CRUD operations, the "retrieve","update" are ok but the problem is with the index operation. With only one field it works and show all records with the default field I declared on resource. Now how to put an array of $fields ?

This is the resource declaration (the "fields" part of the code) :

array(
        'name' => 'fields',
        'optional' => TRUE,
        'type' => 'string',
        'description' => 'The fields to get.',
        'default value' => 'field_title_value',
        'source' => array('param' => 'fields'),
      ),

now here is the function index (callback) :

function _my_module_livre_index($page, $fields, $parameters, $page_size){

$query = db_select('field_data_field_title','t');

services_resource_build_index_query($query, $page, $fields, $parameters, $page_size, 'Livre');
$result = services_resource_execute_index_query($query);

$bien = services_resource_build_index_list($result, 'livre', 'field_title_value');
return array('code'=>'0', 'response'=>$bien);   
}

The doc of services said that $fields is an array of fields i want to return, when i make : $fields = array('field 1','field 2','field 3'); It return an error. If I make a "classic" :

$query = db_select('my table')
->fields('my table', array('field 1','field 2','field 3')

Same error.

Any help please ?

Thank you all.

3
  • "It return an error" - what error, exactly? And if you will edit your question, please try make your title a question, too.
    – Mołot
    Aug 6, 2015 at 7:58
  • God i'm confused It was an error that i've solved before what I wanted to ask is : how to make joins and display fields from different tables on an index operation (with tables that i've joined) this is my question. I think I'll answer this one, and re-answer another question. Thank you Molot and sorry again.
    – Mitch
    Aug 6, 2015 at 8:06
  • Nothing to be sorry about. And self-answers are good thing :)
    – Mołot
    Aug 6, 2015 at 8:08

1 Answer 1

1

The simple db_select with fields make it work easy as that :

function _my_module_livre_index($page, $fields, $parameters, $page_size){

$query = db_select('field_data_field_title','t')
->fields('t', array('field_title_value','entity_id','delta'));//<+++++ whatever you want

services_resource_build_index_query($query, $page, $fields, $parameters, $page_size, 'Livre');
$result = services_resource_execute_index_query($query);

$bien = services_resource_build_index_list($result, 'livre', 'field_title_value');
return array('code'=>'0', 'response'=>$bien);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.