Answers.Body: <p>Have a look at <a href="https://craftcms.stackexchange.com/a/2928/125">the answer</a> given here to someone trying to solve this in the template. With a plugin you'd probably do it like so:</p>
  
  <pre><code>public function getFieldsByEntry($entryModel)
  {
      $fields = array();
      $fieldLayoutFields = $entryModel-&gt;getFieldLayout()-&gt;getFields();
      foreach ($fieldLayoutFields as $fieldLayoutField)
      {
          $fields[] = craft()-&gt;fields-&gt;getFieldById($fieldLayoutField-&gt;fieldId);
      }
      return $fields;
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-25T18:23:14.357Z
Answers.LastActivityDate: 2014-11-25T18:23:14.357Z
Answers.LastEditDate: 2017-04-13T12:51:00.303Z
Answers.UserDisplayName: carlcs
Body: <p>I would like to get all the fields (with their handles and values) for a given global set.</p>
  
  <p>For example : My set is called 'labels'.
  I know I can get the set by using :</p>
  
  <pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::GlobalSet);
  $criteria-&gt;handle = 'labels';
  $labels = $criteria-&gt;first();
  </code></pre>
  
  <p>Or with :</p>
  
  <pre><code>$labels = craft()-&gt;globals-&gt;getSetByHandle('labels');
  </code></pre>
  
  <p>Then I can get a specific data with</p>
  
  <pre><code>$labels-&gt;myDataHandle
  </code></pre>
  
  <p>But how can I get all the data/fields in the set ?
  I would like to have an array or an object with all my labels (in my controller I return the value using returnJson).</p>
  
  <p>Thanks for your help !</p>
  
Tags: <plugin-development><globals>
Title: How can i get all values in a global set
ThreadText: # How can i get all values in a global set
  
  (Asked by: username_0 on 2014-11-25)
  
  I would like to get all the fields (with their handles and values) for a given global set.
  
  For example : My set is called 'labels'.
  I know I can get the set by using :
  
  ```
  $criteria = craft()->elements->getCriteria(ElementType::GlobalSet);
  $criteria->handle = 'labels';
  $labels = $criteria->first();
  
  ```
  
  Or with :
  
  ```
  $labels = craft()->globals->getSetByHandle('labels');
  
  ```
  
  Then I can get a specific data with
  
  ```
  $labels->myDataHandle
  
  ```
  
  But how can I get all the data/fields in the set ?
  I would like to have an array or an object with all my labels (in my controller I return the value using returnJson).
  
  Thanks for your help !
  
  **Tags:** plugin-development, globals
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-11-25. Score: 1
  
  Have a look at [the answer](https://craftcms.stackexchange.com/a/2928/125) given here to someone trying to solve this in the template. With a plugin you'd probably do it like so:
  
  ```
  public function getFieldsByEntry($entryModel)
  {
      $fields = array();
      $fieldLayoutFields = $entryModel->getFieldLayout()->getFields();
      foreach ($fieldLayoutFields as $fieldLayoutField)
      {
          $fields[] = craft()->fields->getFieldById($fieldLayoutField->fieldId);
      }
      return $fields;
  }
  
  ```
  
  
  ---
  
  