I'm writing a simple plugin for 'Craft 2' and It seems that a slug
of an entry is returned if you reffer it like: $entry['slug']
but calling $entry->slug
returns same value as entry title.
Is there an explanation of why it happens and what is the best practice of getting values of the entry fields with a homemade plugin?
Thanks!
God bless ya'll.
$entry->slug
is the correct way.$entry['slug']
will trigger theArrayable
trait and tries to cast your object into an array. Do you do something with your entry or do you change certain values? Is it right after you create a new entry or do you fetch it from your DB? Best practice is to use the object syntax ->$entry->slug
– Robin Schambach Apr 8 '19 at 7:10$entry['slug']
– Robin Schambach Apr 8 '19 at 8:18$entry->slug
should work for sure.. that's why I asked for your complete code. – Robin Schambach Apr 9 '19 at 10:14