I'm usually working on Backends with PHP and ZF/Laminas.

Now I'm building a headless (only Backend) Craft CMS website and have a couple of questions that I didn't find a clear answer on. The Craft CMS project is developed "offline" with Vagrant+Docker and has currently no frontend and won't have it in the near future.

  1. The authors should be able to create an entry (fieldset has only a text) that contains a name. I want to be able to work with the created entry like with a variable/item so I can link other entries and modules to it. Is there a way to do it in the Craft backend itself or in PHP in a controller for example? As I'm working headless, I'm not able to do twig as I don't have the templates or any kind of frontend for now.
  2. The users should be able to upload files and link them to an created item from an author.
  3. What's the best way to fetch these data? I'd like to be able to fetch all (or filter for files or text entries etc.) uploaded files or associated entries to that item.

Is it possible to get the content from specific entries out of my database executing SQL statements in PHP and use the data within a controller?

I'd like to have the newly created entries (by authors) dynamically as items that users can link their uploaded files to.

I'm very thankful for any kind of help!

1 Answer 1


In Craft almost everything is an element type (assets, categories, entries, global sets, matrix blocks, tags and users). If something is an element type you can attach arbitrary fields to it. Using fields like the Assets field, Entries field, Categories field or Users field you can define relations (link) between these elements.

For fetching elements via an API there are these options:

Other non-API options for querying elements are:

  • Thanks for your answer and explaining the element types! My site is currently developed locally with Vagrant + Docker and I'd like to work within the project with my created test entries. So I need to have a GraphQL API first when I want to work with element types within the backend? Isn't it possible to get the content from specific entries from my db executing SQL statements in PHP and use the data within a controller?
    – Ichigo
    Commented Jun 10, 2020 at 13:32
  • I added some non-API options to query for elements. (You definitely don't want to write SQL statements. There are element queries for each type for this purpose.)
    – Johannes
    Commented Jun 10, 2020 at 13:39
  • Thanks a lot for your great help! So I can load the specific entry I want - using the element queries and set the relation to the specific module where users can upload files for example?
    – Ichigo
    Commented Jun 10, 2020 at 14:10
  • What do you mean by module in this case?
    – Johannes
    Commented Jun 10, 2020 at 17:46
  • Sorry! I mean a entry for a whole section. The best case would be: 1. Author creates an entry with a simple word in it like "item". 2. Users upload pictures and can select this newly created item in the upload form (picture upload section in this case) just like a category or a selection box. So items should get created in an entry and dynamically be selectable in the upload form.
    – Ichigo
    Commented Jun 15, 2020 at 6:20

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.