Reorganize and update api examples
[civicrm-core.git] / api / v3 / examples / Contact / FormatSingleValue.php
index 252829cdde475d94f22bf59248950369b131894d..65cd12fc95d21b350853102ff93e08a3537869ac 100644 (file)
@@ -1,30 +1,38 @@
 <?php
-
-/*
- This demonstrates use of the 'format.single_value' param.
+/**
+ * Test Generated example of using contact getvalue API
This demonstrates use of the 'format.single_value' param.
     /* This param causes only a single value of the only entity to be returned as an string.
-    /* it will be ignored if there is not exactly 1 result
+    /* it will be ignored if there is not exactly 1 result *
  */
 function contact_getvalue_example(){
 $params = array(
-  'version' => 3,
   'id' => 17,
   'return' => 'display_name',
 );
 
-  $result = civicrm_api( 'contact','getvalue',$params );
+try{
+  $result = civicrm_api3('contact', 'getvalue', $params);
+}
+catch (CiviCRM_API3_Exception $e) {
+  // handle error here
+  $errorMessage = $e->getMessage();
+  $errorCode = $e->getErrorCode();
+  $errorData = $e->getExtraParams();
+  return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
+}
 
-  return $result;
+return $result;
 }
 
-/*
+/**
  * Function returns array of result expected from previous function
  */
 function contact_getvalue_expectedresult(){
 
   $expectedResult = 'Test Contact';
 
-  return $expectedResult  ;
+  return $expectedResult;
 }
 
 
@@ -48,4 +56,4 @@ function contact_getvalue_expectedresult(){
 *
 * API Standards documentation:
 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
-*/
\ No newline at end of file
+*/