<p>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.</p>

<p>For fetching elements via an API there are these options:</p>

<ul>
<li>the <a href="https://docs.craftcms.com/v3/graphql.html#app" rel="nofollow noreferrer">built-in GraphQL API</a></li>
<li>the <a href="https://plugins.craftcms.com/element-api" rel="nofollow noreferrer">Element API plugin</a></li>
<li>creating a plugin or module and define API endpoints freestyle using the element query builders</li>
</ul>

<p>Other non-API options for querying elements are:</p>

<ul>
<li>use <a href="https://docs.craftcms.com/v3/dev/element-queries/entry-queries.html#example" rel="nofollow noreferrer">element queries</a> in Twig and <a href="https://docs.craftcms.com/v3/dev/tags.html#dd" rel="nofollow noreferrer">dump</a> the result</li>
<li>use <a href="https://docs.craftcms.com/v3/dev/element-queries/entry-queries.html#example" rel="nofollow noreferrer">element queries</a> in PHP and dump the result to the browser</li>
<li>use the REPL via the CLI with <code>./craft shell</code></li>
</ul>

CC BY-SA 4.0
2020-06-10T13:32:06.253Z
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
CC BY-SA 4.0
2020-06-10T13:39:53.763Z
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
CC BY-SA 4.0
2020-06-10T14:10:22.303Z
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
CC BY-SA 4.0
2020-06-10T17:46:10.437Z
What do you mean by module in this case?
Johannes
CC BY-SA 4.0
2020-06-15T06:20:29.613Z
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
CC BY-SA 4.0
2020-06-15T20:58:02.527Z
Hey, I don't feel like I can answer your question this way. It seems to differ from the initial question. Maybe you can ask a new question separately?
Johannes
CC BY-SA 4.0
2020-06-16T07:43:25.480Z
Hey, no worries. I just created a new question!
Ichigo
CC BY-SA 4.0
2020-06-10T13:08:00.910Z
2020-06-10T13:39:24.747Z
2020-06-10T13:39:24.747Z
Johannes
<p>I'm usually working on Backends with PHP and ZF/Laminas. </p>

<p>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.</p>

<ol>
<li>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.</li>
<li>The users should be able to upload files and link them to an created item from an author.</li>
<li>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.</li>
</ol>

<p>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?</p>

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

<p>I'm very thankful for any kind of help!</p>

<craft3><entries><assets><php>
Work with data/content from entries
# Work with data/content from entries

(Asked by: username_0 on 2020-06-10)

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!

**Tags:** craft3, entries, assets, php


---

## 1 answers

### Answer by username_1 on 2020-06-10. Score: 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:

* the [built-in GraphQL API](https://docs.craftcms.com/v3/graphql.html#app)
* the [Element API plugin](https://plugins.craftcms.com/element-api)
* creating a plugin or module and define API endpoints freestyle using the element query builders

Other non-API options for querying elements are:

* use [element queries](https://docs.craftcms.com/v3/dev/element-queries/entry-queries.html#example) in Twig and [dump](https://docs.craftcms.com/v3/dev/tags.html#dd) the result
* use [element queries](https://docs.craftcms.com/v3/dev/element-queries/entry-queries.html#example) in PHP and dump the result to the browser
* use the REPL via the CLI with `./craft shell`

> **Comments:**
> **username_0**: 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?  
> **username_1**: 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.)  
> **username_0**: 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?  
> **username_1**: What do you mean by module in this case?  
> **username_0**: 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.  
> **username_1**: Hey, I don't feel like I can answer your question this way. It seems to differ from the initial question. Maybe you can ask a new question separately?  
> **username_0**: Hey, no worries. I just created a new question!  

---

