How could I expose data using var_dump on Eloquent ORM Laravel? - 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).

Related

Field inside Active Form with Array

I have a dropDownList with multiple select and when i goes to the actionUpdate, i wanna the content of dropDownList selected (correct content).
Array:
array (size=3)
0 =>
object(backend\models\AliHasAliPlanRef)[100]
private '_attributes' (yii\db\BaseActiveRecord) =>
array (size=3)
'ali_s_id' => int 23
'ali_plan_ref_id' => int 50
'weight' => int 22
private '_oldAttributes' (yii\db\BaseActiveRecord) =>
array (size=3)
'ali_s_id' => int 23
'ali_plan_ref_id' => int 50
'weight' => int 22
private '_related' (yii\db\BaseActiveRecord) =>
array (size=0)
empty
private '_errors' (yii\base\Model) => null
private '_validators' (yii\base\Model) => null
private '_scenario' (yii\base\Model) => string 'default' (length=7)
private '_events' (yii\base\Component) =>
array (size=0)
empty
private '_behaviors' (yii\base\Component) =>
array (size=0)
empty
1 =>
object(backend\models\AliHasAliPlanRef)[105]
private '_attributes' (yii\db\BaseActiveRecord) =>
array (size=3)
'ali_s_id' => int 24
'ali_plan_ref_id' => int 50
'weight' => int 33
private '_oldAttributes' (yii\db\BaseActiveRecord) =>
array (size=3)
'ali_s_id' => int 24
'ali_plan_ref_id' => int 50
'weight' => int 33
private '_related' (yii\db\BaseActiveRecord) =>
array (size=0)
empty
private '_errors' (yii\base\Model) => null
private '_validators' (yii\base\Model) => null
private '_scenario' (yii\base\Model) => string 'default' (length=7)
private '_events' (yii\base\Component) =>
array (size=0)
empty
private '_behaviors' (yii\base\Component) =>
array (size=0)
empty
2 =>
object(backend\models\AliHasAliPlanRef)[106]
private '_attributes' (yii\db\BaseActiveRecord) =>
array (size=3)
'ali_s_id' => int 25
'ali_plan_ref_id' => int 50
'weight' => int 4
private '_oldAttributes' (yii\db\BaseActiveRecord) =>
array (size=3)
'ali_s_id' => int 25
'ali_plan_ref_id' => int 50
'weight' => int 4
private '_related' (yii\db\BaseActiveRecord) =>
array (size=0)
empty
private '_errors' (yii\base\Model) => null
private '_validators' (yii\base\Model) => null
private '_scenario' (yii\base\Model) => string 'default' (length=7)
private '_events' (yii\base\Component) =>
array (size=0)
empty
private '_behaviors' (yii\base\Component) =>
array (size=0)
empty
Actually i have this code (and works, but only for the first item selected of array):
<?=
$form->field($ali[0], 'ali_s_id', ['template' => '{label}{input}<span class="help-block">{hint}{error}</span>'])->dropDownList(Category::getHierarchy(), ['size' => 10, 'multiple' => 'multiple'], ['prompt' => Yii::t('app', '-- Select --'),
])
?>
Example of the code above:
I wanna select all (correct) items seletected from DropDownList. I tried too:
<?=
$form->field($ali, 'ali_s_id[]', ['template' => '{label}{input}<span class="help-block">{hint}{error}</span>'])->dropDownList(Category::getHierarchy(), ['size' => 10, 'multiple' => 'multiple'], ['prompt' => Yii::t('app', '-- Select --'),
])
?>
But i received an error:
Call to a member function isAttributeRequired() on array
Result expected:
you have to assign aleardy selected values properly. you can do this two ways.
$ali[0]->ali_s_id = [23, 24, 25];
or
$selectedValues = ["23" => ['selected'=>true], "24" => ['selected'=>true], "25" => ['selected'=>true] ];
<?= $form->field($ali[0], 'ali_s_id', ['template' => '{label}{input}<span class="help-block">{hint}{error}</span>'])->dropDownList(Category::getHierarchy(), ['size' => 10, 'multiple' => 'multiple'],['options' => $selectedValues], 'prompt' => Yii::t('app', '-- Select --')]) ?>

"The Response content must be a string or object implementing __toString(), "boolean" given."

I'm trying to retrieve records using AJAX json and I'm trying to send the result data through a JSON format back to the client. (Below is what I tried)
$vote = users_details::where('vote', '=', 1)->get();
return response()->json(['success' => true, 'vote' => $vote ]);
but unfortunately and sadly not working instead, it throws me this error.
"The Response content must be a string or object implementing
__toString(), "boolean" given."
I tried to
dd(var_dump($vote));
and it shows me the retrieved data so i guess the issue was in the return JSON part and I even tried
$vote = users_details::where('vote', '=', 1)->get()->toJson();
return response()->json(['success' => true, 'vote' => $vote ]);
and it throws me this error (refer below)
Call to undefined function App\Http\Controllers\toJson()
any ideas, help, suggestion, recommendation, clues please?
UPDATE: the retrieved data using
dd(var_dump(users_details::where('vote', '=', 1)->get(['firstname', 'middlename', 'lastname', 'branch', 'position', 'img'])));
the result
object(Illuminate\Database\Eloquent\Collection)[205]
protected 'items' =>
array (size=12)
0 =>
object(App\users_details)[206]
protected 'table' => string 'employee' (length=8)
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=6)
...
protected 'original' =>
array (size=6)
...
protected 'relations' =>
array (size=0)
...
protected 'hidden' =>
array (size=0)
...
protected 'visible' =>
array (size=0)
...
protected 'appends' =>
array (size=0)
...
protected 'fillable' =>
array (size=0)
...
protected 'guarded' =>
array (size=1)
...
protected 'dates' =>
array (size=0)
...
protected 'casts' =>
array (size=0)
...
protected 'touches' =>
array (size=0)
...
protected 'observables' =>
array (size=0)
...
protected 'with' =>
array (size=0)
...
protected 'morphClass' => null
public 'exists' => boolean true
1 =>
object(App\users_details)[207]
protected 'table' => string 'employee' (length=8)
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=6)
...
protected 'original' =>
array (size=6)
...
protected 'relations' =>
array (size=0)
...
protected 'hidden' =>
array (size=0)
...
protected 'visible' =>
array (size=0)
...
protected 'appends' =>
array (size=0)
...
protected 'fillable' =>
array (size=0)
...
protected 'guarded' =>
array (size=1)
...
protected 'dates' =>
array (size=0)
...
protected 'casts' =>
array (size=0)
...
protected 'touches' =>
array (size=0)
...
protected 'observables' =>
array (size=0)
...
protected 'with' =>
array (size=0)
...
protected 'morphClass' => null
public 'exists' => boolean true
2 =>
object(App\users_details)[208]
protected 'table' => string 'employee' (length=8)
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=6)
...
protected 'original' =>
array (size=6)
...
protected 'relations' =>
array (size=0)
...
protected 'hidden' =>
array (size=0)
...
protected 'visible' =>
array (size=0)
...
protected 'appends' =>
array (size=0)
...
protected 'fillable' =>
array (size=0)
...
protected 'guarded' =>
array (size=1)
...
protected 'dates' =>
array (size=0)
...
protected 'casts' =>
array (size=0)
...
protected 'touches' =>
array (size=0)
...
protected 'observables' =>
array (size=0)
...
protected 'with' =>
array (size=0)
...
protected 'morphClass' => null
public 'exists' => boolean true
3 =>
object(App\users_details)[209]
protected 'table' => string 'employee' (length=8)
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=6)
...
protected 'original' =>
array (size=6)
...
protected 'relations' =>
array (size=0)
...
protected 'hidden' =>
array (size=0)
...
protected 'visible' =>
array (size=0)
...
protected 'appends' =>
array (size=0)
...
protected 'fillable' =>
array (size=0)
...
protected 'guarded' =>
array (size=1)
...
protected 'dates' =>
array (size=0)
...
protected 'casts' =>
array (size=0)
...
protected 'touches' =>
array (size=0)
...
protected 'observables' =>
array (size=0)
...
protected 'with' =>
array (size=0)
...
protected 'morphClass' => null
public 'exists' => boolean true
4 =>
object(App\users_details)[210]
protected 'table' => string 'employee' (length=8)
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=6)
...
protected 'original' =>
array (size=6)
...
protected 'relations' =>
array (size=0)
...
protected 'hidden' =>
array (size=0)
...
protected 'visible' =>
array (size=0)
...
protected 'appends' =>
array (size=0)
...
protected 'fillable' =>
array (size=0)
...
protected 'guarded' =>
array (size=1)
...
protected 'dates' =>
array (size=0)
...
protected 'casts' =>
array (size=0)
...
protected 'touches' =>
array (size=0)
...
protected 'observables' =>
array (size=0)
...
protected 'with' =>
array (size=0)
...
protected 'morphClass' => null
public 'exists' => boolean true
5 =>
object(App\users_details)[211]
protected 'table' => string 'employee' (length=8)
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=6)
...
protected 'original' =>
array (size=6)
...
protected 'relations' =>
array (size=0)
...
protected 'hidden' =>
array (size=0)
...
protected 'visible' =>
array (size=0)
...
protected 'appends' =>
array (size=0)
...
protected 'fillable' =>
array (size=0)
...
protected 'guarded' =>
array (size=1)
...
protected 'dates' =>
array (size=0)
...
protected 'casts' =>
array (size=0)
...
protected 'touches' =>
array (size=0)
...
protected 'observables' =>
array (size=0)
...
protected 'with' =>
array (size=0)
...
protected 'morphClass' => null
public 'exists' => boolean true
6 =>
object(App\users_details)[212]
protected 'table' => string 'employee' (length=8)
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=6)
...
protected 'original' =>
array (size=6)
...
protected 'relations' =>
array (size=0)
...
protected 'hidden' =>
array (size=0)
...
protected 'visible' =>
array (size=0)
...
protected 'appends' =>
array (size=0)
...
protected 'fillable' =>
array (size=0)
...
protected 'guarded' =>
array (size=1)
...
protected 'dates' =>
array (size=0)
...
protected 'casts' =>
array (size=0)
...
protected 'touches' =>
array (size=0)
...
protected 'observables' =>
array (size=0)
...
protected 'with' =>
array (size=0)
...
protected 'morphClass' => null
public 'exists' => boolean true
7 =>
object(App\users_details)[213]
protected 'table' => string 'employee' (length=8)
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=6)
...
protected 'original' =>
array (size=6)
...
protected 'relations' =>
array (size=0)
...
protected 'hidden' =>
array (size=0)
...
protected 'visible' =>
array (size=0)
...
protected 'appends' =>
array (size=0)
...
protected 'fillable' =>
array (size=0)
...
protected 'guarded' =>
array (size=1)
...
protected 'dates' =>
array (size=0)
...
protected 'casts' =>
array (size=0)
...
protected 'touches' =>
array (size=0)
...
protected 'observables' =>
array (size=0)
...
protected 'with' =>
array (size=0)
...
protected 'morphClass' => null
public 'exists' => boolean true
8 =>
object(App\users_details)[214]
protected 'table' => string 'employee' (length=8)
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=6)
...
protected 'original' =>
array (size=6)
...
protected 'relations' =>
array (size=0)
...
protected 'hidden' =>
array (size=0)
...
protected 'visible' =>
array (size=0)
...
protected 'appends' =>
array (size=0)
...
protected 'fillable' =>
array (size=0)
...
protected 'guarded' =>
array (size=1)
...
protected 'dates' =>
array (size=0)
...
protected 'casts' =>
array (size=0)
...
protected 'touches' =>
array (size=0)
...
protected 'observables' =>
array (size=0)
...
protected 'with' =>
array (size=0)
...
protected 'morphClass' => null
public 'exists' => boolean true
9 =>
object(App\users_details)[215]
protected 'table' => string 'employee' (length=8)
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=6)
...
protected 'original' =>
array (size=6)
...
protected 'relations' =>
array (size=0)
...
protected 'hidden' =>
array (size=0)
...
protected 'visible' =>
array (size=0)
...
protected 'appends' =>
array (size=0)
...
protected 'fillable' =>
array (size=0)
...
protected 'guarded' =>
array (size=1)
...
protected 'dates' =>
array (size=0)
...
protected 'casts' =>
array (size=0)
...
protected 'touches' =>
array (size=0)
...
protected 'observables' =>
array (size=0)
...
protected 'with' =>
array (size=0)
...
protected 'morphClass' => null
public 'exists' => boolean true
10 =>
object(App\users_details)[216]
protected 'table' => string 'employee' (length=8)
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=6)
...
protected 'original' =>
array (size=6)
...
protected 'relations' =>
array (size=0)
...
protected 'hidden' =>
array (size=0)
...
protected 'visible' =>
array (size=0)
...
protected 'appends' =>
array (size=0)
...
protected 'fillable' =>
array (size=0)
...
protected 'guarded' =>
array (size=1)
...
protected 'dates' =>
array (size=0)
...
protected 'casts' =>
array (size=0)
...
protected 'touches' =>
array (size=0)
...
protected 'observables' =>
array (size=0)
...
protected 'with' =>
array (size=0)
...
protected 'morphClass' => null
public 'exists' => boolean true
11 =>
object(App\users_details)[217]
protected 'table' => string 'employee' (length=8)
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=6)
...
protected 'original' =>
array (size=6)
...
protected 'relations' =>
array (size=0)
...
protected 'hidden' =>
array (size=0)
...
protected 'visible' =>
array (size=0)
...
protected 'appends' =>
array (size=0)
...
protected 'fillable' =>
array (size=0)
...
protected 'guarded' =>
array (size=1)
...
protected 'dates' =>
array (size=0)
...
protected 'casts' =>
array (size=0)
...
protected 'touches' =>
array (size=0)
...
protected 'observables' =>
array (size=0)
...
protected 'with' =>
array (size=0)
...
protected 'morphClass' => null
public 'exists' => boolean true
null

PHP - How can I convert a ParseObject to a JSON?

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!

Can't access elements of merged arrays

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?

How to add button to user profile page in drupal

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

Categories