In the context of a CMS using documents containing data very often is not enough, because they make it hard to work with structured content or data input from external systems. In order to efficiently work with structured content in the context of product information management (PIM), content needs to be grouped into predefined units of data. In pimcore this is accomplished with data objects.
Data objects are literally objects in the sense of object oriented programming. They can be defined through a user friendly graphical user inteface (GUI), but nevertheless in the background a plain php class is created, which can profit from inheritance and can be utilized and accessed programmatically. Data objects can be instantiated and filled in pimcore or they can be served from external systems like CRM, ERP, PIM or asset management systems.
The following code snippet indicates how to access, create and modify an object programmatically:
$myObject = Object_Myclassname::getById(167); $myObject->getName(); $myObject->getDescription(); // ... or you can modifiy data directly with PHP $myObject->setName("My Name"); $myObject->save(); // it's also possible to get an object by an foreign ID $city = Object_City::getByZip(5020,1); // you can also get an object by id where you don't know the type $object = Object_Abstract::getById(235); // or obtain an object by path $object = Object_Abstract::getByPath("/path/to/the/object"); // Create a new object $newObject = Object_Myclassname::create(array( 'name' => 'New Name', 'description' => 'Some description' )); $newObject->setKey(Pimcore_File::getValidFilename('New Name')); $newObject->setParentId(123); $newObject->save();
How object classes are defined and how objects can be listed and batch processed can be found in the following sections about classes, lists and external system interaction
Page: Object Lists
Page: External System Interaction
Page: Inheritance
Page: Custom Icons
Page: Locking fields
Page: Object Variants
Page: Object Preview (since 1.4.2)
Page: Object Tree
Comments (2)
Oct 28, 2010
Tim Glabisch says:
writing custom querys is very simple too, $db = Pimcore_Resource_Mysql::g...writing custom querys is very simple too,
$db = Pimcore_Resource_Mysql::get();
$db->fetchAll('SHOW TABLES FROM pimcore');
$db is an instance of the zend mysql pdo adapter -> http://framework.zend.com/manual/de/zend.db.adapter.html
please note that you should build own models if you want to get data access.
Feb 17, 2011
motv says:
Remember when calling // it's also possible to get an object by an foreign ID $...Remember when calling
// it's also possible to get an object by an foreign ID
$city = Object_City::getByZip(5020,1);
that an Object_List is returned.
To get the first object (or the only one in this list) simply call
$firstCity = $city->current();