In a plugin, I've been advised to try to use craft built-in services instead of direct db queries. So can anyone help with this: For an entry type that includes a categories field, how to get all the categories related to an entry?
I found this:
$entry = craft()->entries->getEntryById($entryId);
So I suppose this might work as well:
$category = craft()->categories->getCategoryById($categoryId);
But I can't find anything intelligible to me under the relations service.
Thanks for any help.
EDIT: On a related note, I see here that in twig you can do this:
{% for entry in craft.entries.section('news').limit(10) %}
<article>
<h1><a href="{{ entry.url }}">{{ entry.title }}</a></h1>
{{ entry.summary }}
<a href="{{ entry.url }}">Continue reading</a>
</article>
{% endfor %}
Whereby Craft/Twig does all the work to find and return the 'summary' field related to each entry. Is there any php statement like this next confused one, following which I could get the categories related to each event?
$events = craft()->entries.section('events').start('<=$toDateYmd').end('OR', '>=$fromDateYmd', '').status('publish');
foreach ($events as $event)
$categories = $event.category;
Thank you!