https://www.drupal.org/documentation/entity-metadata-wrappers
$user_wrapper = &entity_metadata_wrapper('user', $user); $status = $user_wrapper->field_status->value(); //取值 array_push($status,'b'); $user_wrapper->field_status->set($status); // set $user_wrapper->save();
<?php
$wrapper = entity_metadata_wrapper('node', $node);
$wrapper->author->mail->value();
$wrapper->author->mail->set('sepp@example.com')
?>
删除数据:
<?php
// Using an empty ->set(NULL) removes the value - without NULL you'll get a PHP notice that set($value) requires 1 parameter.
$wrapper->field_data->set(NULL);
// And handles correctly the deltas when using multiple values fields
$wrapper->field_data[$delta]->set(NULL);
?>
多值字段取值:
<?php
$first_name = $wrapper->field_tags[0]->name->value();
?>
Example using field collections
<?php
// Populate the fields.
$ewrapper = entity_metadata_wrapper('node', $node);
$ewrapper->field_lead_contact_name->set($contact_name);
$ewrapper->field_lead_contact_phone->set($contact_phone);
$ewrapper->field_lead_contact_email->set($contact_email);
// Create the collection entity and set it's "host".
$collection = entity_create('field_collection_item', array('field_name' => 'field_facilities_requested'));
$collection->setHostEntity('node', $node);
// Now define the collection parameters.
$cwrapper = entity_metadata_wrapper('field_collection_item', $collection);
$cwrapper->field_facility->set(intval($offset));
$cwrapper->save();
// Save.
$ewrapper->save();
?>
相关推荐
这是一个改进,但是您可能会发现自己entity_metadata_wrapper输入entity_metadata_wrapper ! $wrapper = entity_metadata_wrapper('node', $node); 您也可能会想将实体视为对象,并使用自己的自定义方法对其进行...
$ account = entity_metadata_wrapper ( 'user' , $ user );$ account -> employee_number -> set ( 60000 );entity_save ( 'user' , $ account );从用户对象获取数据。 global $ user ;$ account = entity_metadata...
- **`GenericServlet` Wrapper Class**: This abstract class provides a convenient implementation of the `Servlet` interface and can be extended to create custom servlets. - **Thread-Safe Servlets**: ...
template.setEntity("templates/Entity.java.vm"); // 配置拦截器,用于分页 InterceptorConfig interceptorConfig = new InterceptorConfig(); List<AbstractInterceptor> interceptors = new ArrayList(); ...