-
Notifications
You must be signed in to change notification settings - Fork 3
Symphony API ideas
Please add here :-)
Getting an entry from a section, filtering by the name field (long)
$section = Sections::getById(1);
$entries = $section->getEntries();
$entry = $entries->getByName('You')->current();
Getting an entry from a section, filtering by tne name field (short)
$entry = Sections::getById(1)->getEntries()->getByName('Nick')->current();
Getting an entry from an entry id without knowing the section
$entry = Entries::getById(1);
Getting the name and body fields from an entry in section 1, filtering by the name field (long)
$section = Sections::getById(1);
$entries = $section->getEntries();
$entry = $entries->getByName('You');
$fields = $entry->get('name', 'body');
Getting the name field from an entry in a section, filtering by name. (short)
$field = Sections::getById(1)->getEntries()->getByName('You')->getName();
Getting the name field from entry 12
$field = Entries::getById(12)->getName();
-
setSectionId(int $section_id)
sets section ID -
setSectionHandle(string $section_handle)
sets section handle -
getFields()
returns a collection of field data -
getField(string $handle)
returns the data of a field -
setField(string $handle, mixed $value)
sets the data of a field -
save(int $section_id)
persist Entry in a given section -
save(string $section_handle)
persist Entry in a given section -
save(Section $section)
persist Entry in a given section -
asXML()
return the XML representation of an entry
-
get(int $id)
returns an Entry object matching the ID -
get(array $filters, array $options)
returns a collection of Entry objects matching filters, optional array of extra options (fields
,limit
,sort
,direction
)
-
get(int $id)
returns a Section object matching the ID -
get(string $handle)
returns a Section object matching the handle
Get an entry by ID (no section required), two ways:
$entry = Entries::get(123);
$entry = Entries::get(array('system:id' => 123))->current();
If the argument is numeric (ID) then a single Entry
is returned. If an array (of filters) then an iterator or collection of Entry
objects is returned.
Get an entry by title (section required)
$section = Sections::get(1);
$entry = $section->getEntries(array('title' => 'Lorem ipsum'))->current();
The getEntries()
method on a Section
object is the equivalent of Entries::get()
.
Get specific fields of an entry (e.g. data source included elements)
$section = Sections::get(1);
$entry = $section->getEntries(
array(
'title' => 'Lorem ipsum'
),
array(
'fields' => array('title', 'description', 'date'),
'limit' => 20,
'sort' => 'date',
'direction' => 'desc'
)
)->current();
Get the Title field from an entry
$entry = Entries::get(123);
$title = $entry->getField('title');
Create new Entry in section 123
$entry = new Entry();
$entry->setField('title, 'Lorem ipsum');
$entry->save(123);
or
$section = Sections::get(1);
$entry = new Entry();
$entry->setField('title, 'Lorem ipsum');
$entry->save($section);