I´m getting a ParseObject from a query and I need to convert it into json.
When I do a print_r($results) I get a lot of stuff but when I do $json = json_encode($results) and print it, the $json is empty.
Here is the var_dump of $results:
array (size=5)
0 =>
object(Parse\ParseObject)[12]
protected 'serverData' =>
array (size=1)
'Usuario_FK' =>
object(Parse\ParseUser)[15]
...
protected 'operationSet' =>
array (size=0)
empty
private 'estimatedData' =>
array (size=1)
'Usuario_FK' =>
object(Parse\ParseUser)[15]
...
private 'dataAvailability' =>
array (size=1)
'Usuario_FK' => boolean true
private 'className' => string 'Asistencia' (length=10)
private 'objectId' => string 'mdHR3ZZo6z' (length=10)
private 'createdAt' =>
object(DateTime)[13]
public 'date' => string '2015-06-10 01:17:13' (length=19)
public 'timezone_type' => int 2
public 'timezone' => string 'Z' (length=1)
private 'updatedAt' =>
object(DateTime)[14]
public 'date' => string '2015-06-13 13:34:05' (length=19)
public 'timezone_type' => int 2
public 'timezone' => string 'Z' (length=1)
private 'hasBeenFetched' => boolean false
1 =>
object(Parse\ParseObject)[21]
protected 'serverData' =>
array (size=1)
'Usuario_FK' =>
object(Parse\ParseUser)[24]
...
protected 'operationSet' =>
array (size=0)
empty
private 'estimatedData' =>
array (size=1)
'Usuario_FK' =>
object(Parse\ParseUser)[24]
...
private 'dataAvailability' =>
array (size=1)
'Usuario_FK' => boolean true
private 'className' => string 'Asistencia' (length=10)
private 'objectId' => string '3DK19BWOYY' (length=10)
private 'createdAt' =>
object(DateTime)[22]
public 'date' => string '2015-06-10 01:08:14' (length=19)
public 'timezone_type' => int 2
public 'timezone' => string 'Z' (length=1)
private 'updatedAt' =>
object(DateTime)[23]
public 'date' => string '2015-06-13 13:34:09' (length=19)
public 'timezone_type' => int 2
public 'timezone' => string 'Z' (length=1)
private 'hasBeenFetched' => boolean false
2 =>
object(Parse\ParseObject)[30]
protected 'serverData' =>
array (size=1)
'Usuario_FK' =>
object(Parse\ParseUser)[33]
...
protected 'operationSet' =>
array (size=0)
empty
private 'estimatedData' =>
array (size=1)
'Usuario_FK' =>
object(Parse\ParseUser)[33]
...
private 'dataAvailability' =>
array (size=1)
'Usuario_FK' => boolean true
private 'className' => string 'Asistencia' (length=10)
private 'objectId' => string 'x94VIvFpdq' (length=10)
private 'createdAt' =>
object(DateTime)[31]
public 'date' => string '2015-06-10 01:07:38' (length=19)
public 'timezone_type' => int 2
public 'timezone' => string 'Z' (length=1)
private 'updatedAt' =>
object(DateTime)[32]
public 'date' => string '2015-06-13 13:34:11' (length=19)
public 'timezone_type' => int 2
public 'timezone' => string 'Z' (length=1)
private 'hasBeenFetched' => boolean false
3 =>
object(Parse\ParseObject)[39]
protected 'serverData' =>
array (size=1)
'Usuario_FK' =>
object(Parse\ParseUser)[42]
...
protected 'operationSet' =>
array (size=0)
empty
private 'estimatedData' =>
array (size=1)
'Usuario_FK' =>
object(Parse\ParseUser)[42]
...
private 'dataAvailability' =>
array (size=1)
'Usuario_FK' => boolean true
private 'className' => string 'Asistencia' (length=10)
private 'objectId' => string 'z4vtVb9sdU' (length=10)
private 'createdAt' =>
object(DateTime)[40]
public 'date' => string '2015-06-10 01:13:05' (length=19)
public 'timezone_type' => int 2
public 'timezone' => string 'Z' (length=1)
private 'updatedAt' =>
object(DateTime)[41]
public 'date' => string '2015-06-13 13:34:07' (length=19)
public 'timezone_type' => int 2
public 'timezone' => string 'Z' (length=1)
private 'hasBeenFetched' => boolean false
4 =>
object(Parse\ParseObject)[48]
protected 'serverData' =>
array (size=1)
'Usuario_FK' =>
object(Parse\ParseUser)[51]
...
protected 'operationSet' =>
array (size=0)
empty
private 'estimatedData' =>
array (size=1)
'Usuario_FK' =>
object(Parse\ParseUser)[51]
...
private 'dataAvailability' =>
array (size=1)
'Usuario_FK' => boolean true
private 'className' => string 'Asistencia' (length=10)
private 'objectId' => string 'LRsOGB7mjZ' (length=10)
private 'createdAt' =>
object(DateTime)[49]
public 'date' => string '2015-06-10 03:13:36' (length=19)
public 'timezone_type' => int 2
public 'timezone' => string 'Z' (length=1)
private 'updatedAt' =>
object(DateTime)[50]
public 'date' => string '2015-06-13 14:01:03' (length=19)
public 'timezone_type' => int 2
public 'timezone' => string 'Z' (length=1)
private 'hasBeenFetched' => boolean false
And here is after json_encode($results);
[{},{},{},{},{}]
Ideas?
Thank you for your time!
Related
So I had 2 objects that need to work together, one idea that was given to me was to merge them. Did that, using array_merge
But now I can't access the second object from the merged one and I'm stuck. The keys that appear after merge look a little weird, have I used it wrongly?
$merged=array_merge_recursive((array)$post,(array)$image);
And the var_dump for $merged shows me this:
array (size=10)
0 =>
object(Models\Post)[7]
protected 'id' => string '17' (length=2)
protected 'title' => string 'qwq' (length=3)
protected 'body' => string 'wqwq' (length=4)
protected 'views' => string '22' (length=2)
protected 'imgId' => string '17' (length=2)
protected '_attr_accessible' =>
array (size=3)
0 => string 'title' (length=5)
1 => string 'body' (length=4)
2 => string 'views' (length=5)
protected '_validators' =>
array (size=0)
empty
protected '_errors' =>
array (size=0)
empty
protected '_valid' => boolean true
'�*�id' => string '17' (length=2)
'�*�path' => string '/media/' (length=7)
'�*�name' => string 'col_right_callout.jpg' (length=21)
'�*�idPost' => string '0' (length=1)
'�*�description' => string 'wqeqw' (length=5)
'�*�_attr_accessible' =>
array (size=3)
0 => string 'name' (length=4)
1 => string 'path' (length=4)
2 => string 'description' (length=11)
'�*�_validators' =>
array (size=0)
empty
'�*�_errors' =>
array (size=0)
empty
'�*�_valid' => boolean true
How do I access the path or any field from the second part of the array?
Content of $post
array (size=1) 0 =>
object(Models\Post)[7]
protected 'id' => string '17' (length=2)
protected 'title' => string 'qwq' (length=3)
protected 'body' => string 'wqwq' (length=4)
protected 'views' => string '23' (length=2)
protected 'imgId' => string '17' (length=2)
protected '_attr_accessible' =>
array (size=3)
0 => string 'title' (length=5)
1 => string 'body' (length=4)
2 => string 'views' (length=5)
protected '_validators' =>
array (size=0)
empty
protected '_errors' =>
array (size=0)
empty
protected '_valid' => boolean true
Content of $image
object(Models\Image)[9]
protected 'id' => string '17' (length=2)
protected 'path' => string '/media/' (length=7)
protected 'name' => string 'col_right_callout.jpg' (length=21)
protected 'idPost' => string '0' (length=1)
protected 'description' => string 'wqeqw' (length=5)
protected '_attr_accessible' =>
array (size=3)
0 => string 'name' (length=4)
1 => string 'path' (length=4)
2 => string 'description' (length=11)
protected '_validators' =>
array (size=0)
empty
protected '_errors' =>
array (size=0)
empty
protected '_valid' => boolean true
Because image is object, protected and private properties have special character prepended when you cast object to array.
With post you are casting array to array. If you do something like (array)$post[0] you will get same issue with both objects.
Take a look how to get array out of it: How to convert (cast) Object to Array without Class Name prefix in PHP?
I'm new to php development and I want to use var_dump to debug my php program on the client side.
$test= Admin::where("EPANTHERID","=",$email);
var_dump($test);die();
On the client side, I receive this
bject(Illuminate\Database\Eloquent\Builder)[187] protected 'query' => object(Illuminate\Database\Query\Builder)[186] protected 'connection' => object(Illuminate\Database\MySqlConnection)[179] protected 'pdo' => object(PDO)[180] ... protected 'readPdo' => null protected 'reconnector' => object(Closure)[185] ... protected 'queryGrammar' => object(Illuminate\Database\Query\Grammars\MySqlGrammar)[181] ... protected 'schemaGrammar' => null protected 'postProcessor' => object(Illuminate\Database\Query\Processors\MySqlProcessor)[182] ... protected 'events' => object(Illuminate\Events\Dispatcher)[14] ... protected 'paginator' => object(Closure)[184] ... protected 'cache' => object(Closure)[183] ... protected 'fetchMode' => int 8 protected 'transactions' => int 0 protected 'queryLog' => array (size=0) ... protected 'loggingQueries' => boolean true protected 'pretending' => boolean false protected 'database' => string 'xinwen_development' (length=18) protected 'tablePrefix' => string '' (length=0) protected 'config' => array (size=9) ... protected 'grammar' => object(Illuminate\Database\Query\Grammars\MySqlGrammar)[181] protected 'selectComponents' => array (size=11) ... protected 'tablePrefix' => string '' (length=0) protected 'processor' => object(Illuminate\Database\Query\Processors\MySqlProcessor)[182] protected 'bindings' => array (size=5) 'select' => array (size=0) ... 'join' => array (size=0) ... 'where' => array (size=1) ... 'having' => array (size=0) ... 'order' => array (size=0) ... public 'aggregate' => null public 'columns' => null public 'distinct' => boolean false public 'from' => string 'ADMIN' (length=5) public 'joins' => null public 'wheres' => array (size=1) 0 => array (size=5) ... public 'groups' => null public 'havings' => null public 'orders' => null public 'limit' => null public 'offset' => null public 'unions' => null public 'lock' => null protected 'backups' => array (size=0) empty protected 'cacheKey' => null protected 'cacheMinutes' => null protected 'cacheTags' => null protected 'cacheDriver' => null protected 'operators' => array (size=19) 0 => string '=' (length=1) 1 => string '<' (length=1) 2 => string '>' (length=1) 3 => string '<=' (length=2) 4 => string '>=' (length=2) 5 => string '<>' (length=2) 6 => string '!=' (length=2) 7 => string 'like' (length=4) 8 => string 'not like' (length=8) 9 => string 'between' (length=7) 10 => string 'ilike' (length=5) 11 => string '&' (length=1) 12 => string '|' (length=1) 13 => string '^' (length=1) 14 => string '<<' (length=2) 15 => string '>>' (length=2) 16 => string 'rlike' (length=5) 17 => string 'regexp' (length=6) 18 => string 'not regexp' (length=10) protected 'model' => object(Admin)[178] protected 'table' => string 'ADMIN' (length=5) protected 'fillable' => array (size=1) 0 => string 'EPANTHERID' (length=10) protected 'connection' => null protected 'primaryKey' => string 'id' (length=2) protected 'perPage' => int 15 public 'incrementing' => boolean true public 'timestamps' => boolean true protected 'attributes' => array (size=0) empty protected 'original' => array (size=0) empty protected 'relations' => array (size=0) empty protected 'hidden' => array (size=0) empty protected 'visible' => array (size=0) empty protected 'appends' => array (size=0) empty protected 'guarded' => array (size=1) 0 => string '*' (length=1) protected 'dates' => array (size=0) empty protected 'touches' => array (size=0) empty protected 'observables' => array (size=0) empty protected 'with' => array (size=0) empty protected 'morphClass' => null public 'exists' => boolean false protected 'eagerLoad' => array (size=0) empty protected 'macros' => array (size=0) empty protected 'onDelete' => null protected 'passthru' => array (size=12) 0 => string 'toSql' (length=5) 1 => string 'lists' (length=5) 2 => string 'insert' (length=6) 3 => string 'insertGetId' (length=11) 4 => string 'pluck' (length=5) 5 => string 'count' (length=5) 6 => string 'min' (length=3) 7 => string 'max' (length=3) 8 => string 'avg' (length=3) 9 => string 'sum' (length=3) 10 => string 'exists' (length=6) 11 => string 'getBindings' (length=11)
It seems like Eloquent has some mechanism which prevents me from accessing data using var_dump. How could I solve this problem or could anyone show me a better way to debug my php scripts? Thank you.
You should use:
$test= Admin::where("EPANTHERID","=",$email)->get();
or
$test= Admin::where("EPANTHERID","=",$email)->first();
if EPANTHERID is unique and then use var_dump on result.
That's because without get() or first() (and some other methods) you have in your variable only object that holds your query and not the result of running the query (the query in your code has not been launched yet).
I start using drupal(7) 3 days ago and I have small task :
I'm using Profile2 Module to create 2 type of users (candite/employer) and I Want to create a button in the wiew page of the profile of employer.
I create new module for that to test if is an employer profil :
function ab_candidate_app_profile2_view_alter($build) {
$test = $build['field_company_name']['#object'];
if(isset($build))
if($test->type == 'employer_'){
// add the button here
}
}
Thank you for your help
EDIT : and whene i do var_dump($build) i get next result :
array (size=12)
'#view_mode' => string 'account' (length=7)
'field_company_name' =>
array (size=16)
'#theme' => string 'field' (length=5)
'#weight' => int 0
'#title' => string 'Name' (length=4)
'#access' => boolean true
'#label_display' => string 'above' (length=5)
'#view_mode' => string 'account' (length=7)
'#language' => string 'und' (length=3)
'#field_name' => string 'field_company_name' (length=18)
'#field_type' => string 'text' (length=4)
'#field_translatable' => string '0' (length=1)
'#entity_type' => string 'profile2' (length=8)
'#bundle' => string 'employer_' (length=9)
'#object' =>
object(Profile)[56]
public 'pid' => string '6' (length=1)
public 'type' => string 'employer_' (length=9)
public 'label' => string 'Employer ' (length=9)
public 'uid' => string '10' (length=2)
public 'created' => string '1411278976' (length=10)
public 'changed' => string '1411278976' (length=10)
protected 'entityType' => string 'profile2' (length=8)
protected 'entityInfo' =>
array (size=22)
...
protected 'idKey' => string 'pid' (length=3)
protected 'nameKey' => string 'pid' (length=3)
protected 'statusKey' => string 'status' (length=6)
protected 'defaultLabel' => boolean false
public 'field_company_name' =>
array (size=1)
...
public 'field_logo' =>
array (size=1)
...
public 'field_company_description' =>
array (size=1)
...
public 'field_country' =>
array (size=1)
...
public 'rdf_mapping' =>
array (size=0)
...
public 'entity_view_prepared' => boolean true
'#items' =>
array (size=1)
0 =>
array (size=3)
...
'#formatter' => string 'text_default' (length=12)
0 =>
array (size=1)
'#markup' => string 'adel' (length=4)
'field_logo' =>
array (size=16)
'#theme' => string 'field' (length=5)
'#weight' => int 2
'#title' => string 'Logo' (length=4)
'#access' => boolean true
'#label_display' => string 'above' (length=5)
'#view_mode' => string 'account' (length=7)
'#language' => string 'und' (length=3)
'#field_name' => string 'field_logo' (length=10)
'#field_type' => string 'image' (length=5)
'#field_translatable' => string '0' (length=1)
'#entity_type' => string 'profile2' (length=8)
'#bundle' => string 'employer_' (length=9)
'#object' =>
object(Profile)[56]
public 'pid' => string '6' (length=1)
public 'type' => string 'employer_' (length=9)
public 'label' => string 'Employer ' (length=9)
public 'uid' => string '10' (length=2)
public 'created' => string '1411278976' (length=10)
public 'changed' => string '1411278976' (length=10)
protected 'entityType' => string 'profile2' (length=8)
protected 'entityInfo' =>
array (size=22)
...
protected 'idKey' => string 'pid' (length=3)
protected 'nameKey' => string 'pid' (length=3)
protected 'statusKey' => string 'status' (length=6)
protected 'defaultLabel' => boolean false
public 'field_company_name' =>
array (size=1)
...
public 'field_logo' =>
array (size=1)
...
public 'field_company_description' =>
array (size=1)
...
public 'field_country' =>
array (size=1)
...
public 'rdf_mapping' =>
array (size=0)
...
public 'entity_view_prepared' => boolean true
'#items' =>
array (size=1)
0 =>
array (size=13)
...
'#formatter' => string 'image' (length=5)
0 =>
array (size=4)
'#theme' => string 'image_formatter' (length=15)
'#item' =>
array (size=13)
...
'#image_style' => string '' (length=0)
'#path' => string '' (length=0)
'field_company_description' =>
array (size=16)
'#theme' => string 'field' (length=5)
'#weight' => int 3
'#title' => string 'Description' (length=11)
'#access' => boolean true
'#label_display' => string 'above' (length=5)
'#view_mode' => string 'account' (length=7)
'#language' => string 'und' (length=3)
'#field_name' => string 'field_company_description' (length=25)
'#field_type' => string 'text_long' (length=9)
'#field_translatable' => string '0' (length=1)
'#entity_type' => string 'profile2' (length=8)
'#bundle' => string 'employer_' (length=9)
'#object' =>
object(Profile)[56]
public 'pid' => string '6' (length=1)
public 'type' => string 'employer_' (length=9)
public 'label' => string 'Employer ' (length=9)
public 'uid' => string '10' (length=2)
public 'created' => string '1411278976' (length=10)
public 'changed' => string '1411278976' (length=10)
protected 'entityType' => string 'profile2' (length=8)
protected 'entityInfo' =>
array (size=22)
...
protected 'idKey' => string 'pid' (length=3)
protected 'nameKey' => string 'pid' (length=3)
protected 'statusKey' => string 'status' (length=6)
protected 'defaultLabel' => boolean false
public 'field_company_name' =>
array (size=1)
...
public 'field_logo' =>
array (size=1)
...
public 'field_company_description' =>
array (size=1)
...
public 'field_country' =>
array (size=1)
...
public 'rdf_mapping' =>
array (size=0)
...
public 'entity_view_prepared' => boolean true
'#items' =>
array (size=1)
0 =>
array (size=3)
...
'#formatter' => string 'text_default' (length=12)
0 =>
array (size=1)
'#markup' => string 'teeeeeeeeeeeeeeeeeeeest' (length=23)
'field_country' =>
array (size=16)
'#theme' => string 'field' (length=5)
'#weight' => int 4
'#title' => string 'Country' (length=7)
'#access' => boolean true
'#label_display' => string 'above' (length=5)
'#view_mode' => string 'account' (length=7)
'#language' => string 'und' (length=3)
'#field_name' => string 'field_country' (length=13)
'#field_type' => string 'list_text' (length=9)
'#field_translatable' => string '0' (length=1)
'#entity_type' => string 'profile2' (length=8)
'#bundle' => string 'employer_' (length=9)
'#object' =>
object(Profile)[56]
public 'pid' => string '6' (length=1)
public 'type' => string 'employer_' (length=9)
public 'label' => string 'Employer ' (length=9)
public 'uid' => string '10' (length=2)
public 'created' => string '1411278976' (length=10)
public 'changed' => string '1411278976' (length=10)
protected 'entityType' => string 'profile2' (length=8)
protected 'entityInfo' =>
array (size=22)
...
protected 'idKey' => string 'pid' (length=3)
protected 'nameKey' => string 'pid' (length=3)
protected 'statusKey' => string 'status' (length=6)
protected 'defaultLabel' => boolean false
public 'field_company_name' =>
array (size=1)
...
public 'field_logo' =>
array (size=1)
...
public 'field_company_description' =>
array (size=1)
...
public 'field_country' =>
array (size=1)
...
public 'rdf_mapping' =>
array (size=0)
...
public 'entity_view_prepared' => boolean true
'#items' =>
array (size=1)
0 =>
array (size=1)
...
'#formatter' => string 'list_default' (length=12)
0 =>
array (size=1)
'#markup' => string 'Malaysia (MY)' (length=13)
'#pre_render' =>
array (size=1)
0 => string '_field_extra_fields_pre_render' (length=30)
'#entity_type' => string 'profile2' (length=8)
'#bundle' => string 'employer_' (length=9)
'#theme' => string 'entity' (length=6)
'#entity' =>
object(Profile)[56]
public 'pid' => string '6' (length=1)
public 'type' => string 'employer_' (length=9)
public 'label' => string 'Employer ' (length=9)
public 'uid' => string '10' (length=2)
public 'created' => string '1411278976' (length=10)
public 'changed' => string '1411278976' (length=10)
protected 'entityType' => string 'profile2' (length=8)
protected 'entityInfo' =>
array (size=22)
'label' => string 'Profile' (length=7)
'plural label' => string 'Profiles' (length=8)
'description' => string 'Profile2 user profiles.' (length=23)
'entity class' => string 'Profile' (length=7)
'controller class' => string 'EntityAPIController' (length=19)
'base table' => string 'profile' (length=7)
'fieldable' => boolean true
'view modes' =>
array (size=1)
...
'entity keys' =>
array (size=4)
...
'bundles' =>
array (size=2)
...
'bundle keys' =>
array (size=1)
...
'label callback' => string 'entity_class_label' (length=18)
'uri callback' => string 'entity_class_uri' (length=16)
'access callback' => string 'profile2_access' (length=15)
'module' => string 'profile2' (length=8)
'metadata controller class' => string 'Profile2MetadataController' (length=26)
'static cache' => boolean true
'field cache' => boolean true
'load hook' => string 'profile2_load' (length=13)
'translation' =>
array (size=0)
...
'schema_fields_sql' =>
array (size=1)
...
'configuration' => boolean false
protected 'idKey' => string 'pid' (length=3)
protected 'nameKey' => string 'pid' (length=3)
protected 'statusKey' => string 'status' (length=6)
protected 'defaultLabel' => boolean false
public 'field_company_name' =>
array (size=1)
'und' =>
array (size=1)
...
public 'field_logo' =>
array (size=1)
'und' =>
array (size=1)
...
public 'field_company_description' =>
array (size=1)
'und' =>
array (size=1)
...
public 'field_country' =>
array (size=1)
'und' =>
array (size=1)
...
public 'rdf_mapping' =>
array (size=0)
empty
public 'entity_view_prepared' => boolean true
'#language' => string 'en' (length=2)
'#page' => null
I solve it by overrieding the user-profile.tpl.php with this code :
<?php print render($user_profile);
if(isset($user_profile['profile_employer_'])){
$account_info=menu_get_object('user');
$acount_id = $account_info->uid;
// var_dump($account_info);die();
echo 'Apply Now';
}
?>
I overied this file in the next path :
C:\wamp\www\jobPortal\themes\bartik\templates\
I am assuming that you need to add a button on profile display and not specifically a "view" from Views module. In that case you must use
hook_node_view
Here is an example
https://www.drupal.org/node/1993368#comment-7406538
or a check out more elaborative answer at
Drupal 7 hook_node_view add a form to the content of a node. You can add a button in the form and call on display.
In case you are using a view from "Views" module, I would suggest to better create a block in your code and place on the particular page rather than altering views. Altered views can be really difficult to maintain. It is best to keep them only for displaying DB content and not embedding forms.
Still you might like to go through the comments on this thread regarding a similar query https://drupal.stackexchange.com/questions/91186/how-do-i-embed-a-node-creation-form-inside-a-view
Is there a way to get the values of a JSON object member variable from a array without looping the objects? Similar to how call_user_func_array would work but for member variables?
E.g.
array 0 =>
object(stdClass)[402]
public 'id' => int 196
public 'creditLimit' => string '0' (length=1)
public 'state' => int 0 1 =>
object(stdClass)[403]
public 'id' => int 197
public 'creditLimit' => string '0' (length=1)
public 'state' => int 0 2 =>
object(stdClass)[404]
public 'id' => int 3269
public 'creditLimit' => string '0' (length=1)
public 'state' => int 0 3 =>
object(stdClass)[405]
public 'id' => int 3334
public 'creditLimit' => string '0' (length=1)
public 'state' => int 0 4 =>
object(stdClass)[406]
public 'id' => int 5831
public 'creditLimit' => string '0' (length=1)
public 'state' => int 0 5 =>
object(stdClass)[379]
public 'id' => int 6358
public 'creditLimit' => string '0' (length=1)
public 'state' => int 0 6 =>
object(stdClass)[400]
public 'id' => int 6592
public 'creditLimit' => string '0' (length=1)
public 'state' => int 0
In one single call I'm trying to obtain the summation of creditLimit.
Pass "true" to json_decode to get a regular array.
I have a weird error in Doctrine 2
Repository function
$query = $this->_em->createQuery('SELECT c FROM \Model\Entity\Cluster c
WHERE c.publisherid = :publisherid');
$query->setParameter("publisherid", (int)$publisher_id);
var_dump($query->getResult());
var_dump($query->getArrayResult());
And what we have
Objects:
array (size=8)
0 =>
object(Model\Entity\Cluster)[**396**]
private 'psiteid' => int 215
private 'psiteclusterdate' =>
object(DateTime)[371]
public 'date' => string '**2011-12-20** 00:00:00' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Moscow' (length=13)
private 'publisherid' => int 276
private 'views' => int 14657
private 'clicks' => int 6220
...
1 =>
object(Model\Entity\Psitecluster)[**396**]
private 'psiteid' => int 215
private 'psiteclusterdate' =>
object(DateTime)[371]
public 'date' => string '**2011-12-20** 00:00:00' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Moscow' (length=13)
private 'publisherid' => int 276
private 'views' => int 14657
private 'clicks' => int 6220
...
Rows with key 0-3 dublicate this object (396) and other rows dublicate second object.
When i dump as array:
array (size=8)
0 =>
array (size=22)
'psiteid' => int 215
'psiteclusterdate' =>
object(DateTime)[367]
public 'date' => string '**2011-12-20** 00:00:00' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Moscow' (length=13)
'publisherid' => int 276
'views' => int 14657
'clicks' => int 6220
....
1 =>
array (size=22)
'psiteid' => int 215
'psiteclusterdate' =>
object(DateTime)[396]
public 'date' => string '2011-12-21 00:00:00' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Moscow' (length=13)
'publisherid' => int 276
'views' => int 10166
'clicks' => int 4028
All the rows are different in array. What's wrong with objects?
I solved a problem. It is a bug in Doctrine2. I created bug report here http://doctrine-project.org/jira/browse/DDC-1780
You can fix with in you project (if you can edit Doctrine library files).
Just add
if ($id[$fieldName] instanceof \DateTime) {
$id[$fieldName] = $id[$fieldName]->getTimestamp();
}`
in foreach loop.