Search

"Simple Questions" that i struggle every day whenever i need to do custom events and load and save data with Symphony

How????

  • If I have a section for example "Books" and entry id = 99.

How can i?

Load the entry ?

Like:

$data = $book->load(90);

Am i gonna have an array with all data from this section?

for example:

$data = $book->load(99);
$data = array(
    id => 99,
    name => 'Book'
);

Now, if i have to save a section in case:

$data = $book->load(99);
$book->name = "New Name";
$book->save();

will save?

And of course the delete?

$book->delete(99); ???

Simple questions that i couldnt find anywhere yet?

Will wait the gurus around :)

Cheers.

Try these:

// fetch the Entry with ID 99
$entry = EntryManager::fetch( 99 );
if( is_array( $entry ) ) $entry = current( $entry );

/** @var $entry Entry */
if( !$entry instanceof Entry ){
    // entry with ID 99 doesn't exist
}

// get an array of data for all fields, by field ID
// @see Entry::getData()
$data = $entry->getData();

// get data for field with handle = 'name'
$section_id = SectionManager::fetchIDFromHandle( 'books' );
$f_name_id = FieldManager::fetchFieldIDFromElementName( 'name', $section_id );
$name = $entry->getData( $f_name_id );

// delete the Entry with ID 99
EntryManager::delete( 99 );

In case you haven't already seen the API documentation:

EntryManager

Entry

Is there a way to get the XML of an entry after fetching it? I've done it before using the datasource manager but I'm looking for something more direct.

@touchstone, this Gist I made after fumbling around with a custom event might be of some use:

Notes on getting data from within Symphony CMS

Thanks for the answer guys.... Im having a look into the documentation!!!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details