Hi Guys :) I have something like that:
Array
(
[0] => Ideneal\OpenLoad\Entity\RemoteUploadStatus Object
(
[remoteUpload:Ideneal\OpenLoad\Entity\RemoteUploadStatus:private] => Ideneal\OpenLoad\Entity\RemoteUpload Object
(
[id:Ideneal\OpenLoad\Entity\RemoteUpload:private] => xxxx
[folderId:Ideneal\OpenLoad\Entity\RemoteUpload:private] => xxxx
)
[remoteUrl:Ideneal\OpenLoad\Entity\RemoteUploadStatus:private] => https://openload.co/embed/xxxxx
[status:Ideneal\OpenLoad\Entity\RemoteUploadStatus:private] => finished
[bytesLoaded:Ideneal\OpenLoad\Entity\RemoteUploadStatus:private] =>
[bytesTotal:Ideneal\OpenLoad\Entity\RemoteUploadStatus:private] =>
[addedDate:Ideneal\OpenLoad\Entity\RemoteUploadStatus:private] => DateTime Object
(
[date] => 2017-07-21 10:53:55.000000
[timezone_type] => 3
[timezone] => Europe/Berlin
)
[lastUpdateDate:Ideneal\OpenLoad\Entity\RemoteUploadStatus:private] => DateTime Object
(
[date] => 2017-07-21 10:53:55.000000
[timezone_type] => 3
[timezone] => Europe/Berlin
)
[fileId:Ideneal\OpenLoad\Entity\RemoteUploadStatus:private] => xxxx
[url:Ideneal\OpenLoad\Entity\RemoteUploadStatus:private] => https://openload.co/f/xxxx <------------ Here is what I want to write to a variable
)
)
(At the end of the code is a comment)
How to do that ?
I tried something like that: print_r($myarray[0][url:Ideneal\OpenLoad\Entity\RemoteUploadStatus:private])
and nothing.
Try to use RemoteUploadStatus object methods:
$myarray[0]->getUrl();
Ref.: https://github.com/Ideneal/OpenLoad/blob/master/src/Entity/RemoteUploadStatus.php
Related
I have a tried numerous examples on stack already and I cant seem to get this right! I am trying to pull the date from this DateTime Object also the reason for the two lines of time was because I was trying different methods and compare the return.
[created] => DateTime Object
(
[date] => 2019-06-06 15:22:25.720000
[timezone_type] => 1
[timezone] => +00:00
)
but for some reason i'm getting the completely wrong date and time.
19-09-04 22:37:18
1970-01-01 01:00:00
19-09-04 22:37:18
1970-01-01 01:00:00
19-09-04 22:37:18
1970-01-01 01:00:00
19-09-04 22:37:18
1970-01-01 01:00:00
I've tried the following:
JSON Array to PHP DateTime
PHP date time from string
Arrays - foreach brings ->Fatal error: Cannot use object of type
PHP CODE:
<?php
$vPaccomments = $issue->fields->comment->comments;
foreach ($vPaccomments as $vPaccomment) {
$vPacAvatarUrl = $vPaccomment->author->avatarUrls;
$size16 = "16x16";
$vPacCreated = $vPaccomment->created;
$vPacDate = $vPacCreated->date;
$vPacDateConv = date('Y-m-d H:i:s',strtotime($vPacDate));
$dateTime = new DateTime($vPacDate);
echo $dateTime->format('y-m-d H:i:s');
echo '<pre>'; print_r($vPacDateConv);
echo "<div class=\"col\">";
//echo "<img width=\"16px\" src=\"" . $vPacAvatarUrl[$size16] . "\"> " . "<font color=\"#0015ff\">" .$vPaccomment->author->displayName ."</font> added a comment - " . date_format($vPacCreateDate, 'Y-m-d H:i:s');
echo "<br>";
echo "<hr>";
echo "</div>";
}
?>
If I echo '<pre>'; print_r($vPacCreated);
I get the correct results i want to grab
DateTime Object
(
[date] => 2019-06-06 15:22:25.720000
[timezone_type] => 1
[timezone] => +00:00
)
DateTime Object
(
[date] => 2019-06-07 13:58:31.970000
[timezone_type] => 1
[timezone] => +00:00
)
DateTime Object
(
[date] => 2019-06-17 14:07:23.040000
[timezone_type] => 1
[timezone] => +00:00
)
DateTime Object
(
[date] => 2019-06-17 14:25:13.840000
[timezone_type] => 1
[timezone] => +00:00
)
Here is the portion of the values:
[comment] => JiraRestApi\Issue\Comments Object
(
[startAt] => 0
[maxResults] => 4
[total] => 4
[comments] => Array
(
[0] => JiraRestApi\Issue\Comment Object
(
[self] => https://xxx/rest/api/2/xxx
[id] => xxx
[author] => JiraRestApi\Issue\Reporter Object
(
[self] => https://xxx/rest/api/2/xxx
[name] => xxx
[emailAddress] => xxx
[avatarUrls] => Array
(
[48x48] => https://xxx/secure/useravatar?avatarId=xxx
[24x24] => https://xxx/secure/useravatar?size=small&avatarId=xxx
[16x16] => https://xxx/secure/useravatar?size=xsmall&avatarId=xxx
[32x32] => https://xxx/secure/useravatar?size=medium&avatarId=xxx
)
[displayName] => xxx
[active] => 1
[wantUnassigned:JiraRestApi\Issue\Reporter:private] =>
[accountId] =>
[key] => xxx
[timeZone] => America/New_York
)
[body] => xxx
CREATED ON:6/6/2019
COPIED TO:\\xxx
[updateAuthor] => JiraRestApi\Issue\Reporter Object
(
[self] => https://xxx/rest/api/2/xxx
[name] => xxx
[emailAddress] => xxx
[avatarUrls] => Array
(
[48x48] => https://xxx/secure/useravatar?avatarId=xxx
[24x24] => https://xxx/secure/useravatar?size=small&avatarId=xxx
[16x16] => https://xxx/secure/useravatar?size=xsmall&avatarId=xxx
[32x32] => https://xxx/secure/useravatar?size=medium&avatarId=xxx
)
[displayName] => xxx
[active] => 1
[wantUnassigned:JiraRestApi\Issue\Reporter:private] =>
[accountId] =>
[key] => xxx
[timeZone] => America/New_York
)
[created] => DateTime Object
(
[date] => 2019-06-06 15:22:25.720000
[timezone_type] => 1
[timezone] => +00:00
)
Judging from your input data, it looks like $vPacCreated is already a DateTime object, so you should be able to just
echo $vPacCreated->format('Y-m-d H:i:s');
I'm using php sdk 5 reading all post from my page using the Facebook API.
My problem is just to echo the created_time from the response data to no avail.
try {
// Get a list of pages with you as admin
$posts_request = $fb->get('/'.$fbpageid.'/feed?fields=id,message,created_time');
} catch (FacebookRequestException $e) {
echo 'Request error: ' . $e->getMessage();
exit;
}
And here a sample of the response data:
Array (
[0] => Array (
[id] => 2072715452753496_2089871617704546
[message] => sample of post number one
[created_time] => DateTime Object (
[date] => 2018-02-15 02:39:28.000000
[timezone_type] => 1
[timezone] => +00:00
)
)
[1] => Array (
[id] => 2072715452753496_2082500291775012
[message] => sample post number two
[created_time] => DateTime Object (
[date] => 2018-02-10 10:24:53.000000
[timezone_type] => 1
[timezone] => +00:00
)
)
[2] => Array (
[id] => 2072715452753496_2072717852753256
[created_time] => DateTime Object (
[date] => 2018-02-03 09:56:16.000000
[timezone_type] => 1
[timezone] => +00:00
)
)
[3] => Array (
[id] => 2072715452753496_2072717476086627
[created_time] => DateTime Object (
[date] => 2018-02-03 09:55:46.000000
[timezone_type] => 1 [timezone] => +00:00
)
)
)
try this :
try {
// Get a list of pages with you as admin
$posts_request = $fb->get('/'.$fbpageid.'feed?fields=id,message,created_time');
foreach ($posts_request as $key => $value){
echo $value['created_time']->format('Y-m-d'); // format your DateTime object
}
}
this could https://paulund.co.uk/datetime-php
I have a simple code and when I print_r it, this one is the output:
Array
(
[0] => App\Entities\EibPerson Object
(
[personId:App\Entities\EibPerson:private] => 10025
[createdBy:App\Entities\EibPerson:private] => 1
[createdOn:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 2016-12-06 08:33:59.000000
[timezone_type] => 1
[timezone] => +03:00
)
[modifiedBy:App\Entities\EibPerson:private] => 1
[modifiedOn:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 2016-12-06 08:33:59.000000
[timezone_type] => 1
[timezone] => +03:00
)
[recordVersion:App\Entities\EibPerson:private] => 1
[activeFlag:App\Entities\EibPerson:private] => 1
[firstName:App\Entities\EibPerson:private] => test person name
[middleName:App\Entities\EibPerson:private] => test middle
[lastName:App\Entities\EibPerson:private] => test last name
[displayName:App\Entities\EibPerson:private] => sorxrob
[dateOfBirth:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 1992-10-01 03:00:00.000000
[timezone_type] => 1
[timezone] => +03:00
)
[landlineNumber:App\Entities\EibPerson:private] => 2312321313131
[mobileNumber:App\Entities\EibPerson:private] => 876543454
[emailAddress:App\Entities\EibPerson:private] => sorianorobertc#gmail.com
[heightInches:App\Entities\EibPerson:private] => 6
[inseamLengthInches:App\Entities\EibPerson:private] => 6
[weightInKgs:App\Entities\EibPerson:private] => 80.00
[profilePictureUrl:App\Entities\EibPerson:private] =>
[sourceDesc:App\Entities\EibPerson:private] => testsourceDesc
[remarks:App\Entities\EibPerson:private] => test remarks test
[memberId:App\Entities\EibPerson:private] =>
[externalReferenceId:App\Entities\EibPerson:private] =>
[genderEnumRid:App\Entities\EibPerson:private] =>
[address:App\Entities\EibPerson:private] =>
[tshirtSizeEnumRid:App\Entities\EibPerson:private] =>
[bloodGroupEnumRid:App\Entities\EibPerson:private] =>
[managingBranch:App\Entities\EibPerson:private] =>
[foodPreferenceEnumRid:App\Entities\EibPerson:private] =>
[sourceEnumRid:App\Entities\EibPerson:private] =>
[sourceDetailRid:App\Entities\EibPerson:private] =>
[externalSourceSysEnumRid:App\Entities\EibPerson:private] =>
)
[1] => App\Entities\EibPerson Object
(
[personId:App\Entities\EibPerson:private] => 10026
[createdBy:App\Entities\EibPerson:private] => 1
[createdOn:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 2016-12-06 08:36:03.000000
[timezone_type] => 1
[timezone] => +03:00
)
[modifiedBy:App\Entities\EibPerson:private] => 1
[modifiedOn:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 2016-12-06 08:36:03.000000
[timezone_type] => 1
[timezone] => +03:00
)
[recordVersion:App\Entities\EibPerson:private] => 1
[activeFlag:App\Entities\EibPerson:private] => 1
[firstName:App\Entities\EibPerson:private] => test person name
[middleName:App\Entities\EibPerson:private] => test middle
[lastName:App\Entities\EibPerson:private] => test last name
[displayName:App\Entities\EibPerson:private] => sorxrob
[dateOfBirth:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 1992-10-01 03:00:00.000000
[timezone_type] => 1
[timezone] => +03:00
)
[landlineNumber:App\Entities\EibPerson:private] => 2312321313131
[mobileNumber:App\Entities\EibPerson:private] => 876543454
[emailAddress:App\Entities\EibPerson:private] => sorianorobertc#gmail.com
[heightInches:App\Entities\EibPerson:private] => 6
[inseamLengthInches:App\Entities\EibPerson:private] => 6
[weightInKgs:App\Entities\EibPerson:private] => 80.00
[profilePictureUrl:App\Entities\EibPerson:private] =>
[sourceDesc:App\Entities\EibPerson:private] => testsourceDesc
[remarks:App\Entities\EibPerson:private] => test remarks test
[memberId:App\Entities\EibPerson:private] =>
[externalReferenceId:App\Entities\EibPerson:private] =>
[genderEnumRid:App\Entities\EibPerson:private] =>
[address:App\Entities\EibPerson:private] =>
[tshirtSizeEnumRid:App\Entities\EibPerson:private] =>
[bloodGroupEnumRid:App\Entities\EibPerson:private] =>
[managingBranch:App\Entities\EibPerson:private] =>
[foodPreferenceEnumRid:App\Entities\EibPerson:private] =>
[sourceEnumRid:App\Entities\EibPerson:private] =>
[sourceDetailRid:App\Entities\EibPerson:private] =>
[externalSourceSysEnumRid:App\Entities\EibPerson:private] =>
)
[2] => App\Entities\EibPerson Object
(
[personId:App\Entities\EibPerson:private] => 10027
[createdBy:App\Entities\EibPerson:private] => 1
[createdOn:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 2016-12-06 08:37:25.000000
[timezone_type] => 1
[timezone] => +03:00
)
[modifiedBy:App\Entities\EibPerson:private] => 1
[modifiedOn:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 2016-12-06 08:37:25.000000
[timezone_type] => 1
[timezone] => +03:00
)
[recordVersion:App\Entities\EibPerson:private] => 1
[activeFlag:App\Entities\EibPerson:private] => 1
[firstName:App\Entities\EibPerson:private] => test person name
[middleName:App\Entities\EibPerson:private] => test middle
[lastName:App\Entities\EibPerson:private] => test last name
[displayName:App\Entities\EibPerson:private] => sorxrob
[dateOfBirth:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 1992-10-01 03:00:00.000000
[timezone_type] => 1
[timezone] => +03:00
)
[landlineNumber:App\Entities\EibPerson:private] => 2312321313131
[mobileNumber:App\Entities\EibPerson:private] => 876543454
[emailAddress:App\Entities\EibPerson:private] => sorianorobertc#gmail.com
[heightInches:App\Entities\EibPerson:private] => 6
[inseamLengthInches:App\Entities\EibPerson:private] => 6
[weightInKgs:App\Entities\EibPerson:private] => 80.00
[profilePictureUrl:App\Entities\EibPerson:private] =>
[sourceDesc:App\Entities\EibPerson:private] => testsourceDesc
[remarks:App\Entities\EibPerson:private] => test remarks test
[memberId:App\Entities\EibPerson:private] =>
[externalReferenceId:App\Entities\EibPerson:private] =>
[genderEnumRid:App\Entities\EibPerson:private] =>
[address:App\Entities\EibPerson:private] =>
[tshirtSizeEnumRid:App\Entities\EibPerson:private] =>
[bloodGroupEnumRid:App\Entities\EibPerson:private] =>
[managingBranch:App\Entities\EibPerson:private] =>
[foodPreferenceEnumRid:App\Entities\EibPerson:private] =>
[sourceEnumRid:App\Entities\EibPerson:private] =>
[sourceDetailRid:App\Entities\EibPerson:private] =>
[externalSourceSysEnumRid:App\Entities\EibPerson:private] =>
)
)
My code:
$person = $this->em->getRepository('App\Entities\EibPerson')->findAll();
print_r($person);
What I actually want is to only get this:
How can I possibly do that? Because I want to json_encode the array but im getting an empty json..
Debug with max depth
You could use maxDepth variable of Doctrine Dump.
You can use \Doctrine\Common\Util\Debug::dump($variable, $depth); it displays doctrine output without the proxy information.
More readable output
If you are using symfony 2.6 or more, I strongly advice you to use dump() instead of var_dump() or print_r().
Dump shows a well formated and colored output, and you can expand/hide rows.
Finally... to json
To export object(s) to json, I advice you to use serializer and normalizer services, you can find here in the documentation
I just added PHP ActiveRecord to my CodeIgniter installation. I'm running a few tests now and am very confused by a few things. I have a products table in mysql, and when I use ActiveRecord to retrieve the first row in the table, this is the output I get:
Product Object
(
[errors] =>
[attributes:ActiveRecord\Model:private] => Array
(
[id] => 1
[ext_id] => 347
[ext_type_id] => 1
[sku] => SYB-RIU-SUP
[url] => http://domain.com
[name] => SUP Wall Storage Rack
[thumbnail_url] => https://thumburl.com
[sort_order] => 20
[profitability] => 40
[last_google_update] => ActiveRecord\DateTime Object
(
[model:ActiveRecord\DateTime:private] => Product Object
*RECURSION*
[attribute_name:ActiveRecord\DateTime:private] => last_google_update
[date] => 2014-05-21 05:01:12
[timezone_type] => 3
[timezone] => UTC
)
[last_internal_update] =>
[discontinued] => 0
[stock_notes] =>
[deleted] => 0
[created_on] => ActiveRecord\DateTime Object
(
[model:ActiveRecord\DateTime:private] => Product Object
*RECURSION*
[attribute_name:ActiveRecord\DateTime:private] => created_on
[date] => 2014-03-25 22:31:58
[timezone_type] => 3
[timezone] => UTC
)
)
[__dirty:ActiveRecord\Model:private] => Array
(
)
[__readonly:ActiveRecord\Model:private] =>
[__relationships:ActiveRecord\Model:private] => Array
(
)
[__new_record:ActiveRecord\Model:private] =>
)
What do the *RECURSION* lines mean in the object? Is that expected or is that a problem? Also, let's say I need to access the last_google_update field, I do the following:
$product = Product::first();
$date = $product->last_google_update;
print_r($date);
This outputs the following:
ActiveRecord\DateTime Object
(
[model:ActiveRecord\DateTime:private] => Product Object
(
[errors] =>
[attributes:ActiveRecord\Model:private] => Array
(
[id] => 1
[ext_id] => 347
[ext_type_id] => 1
[sku] => SYB-RIU-SUP
[url] => http://www.storeyourboard.com/sup-storage-rack.html
[name] => SUP Wall Storage Rack
[thumbnail_url] => https://cdn2.bigcommerce.com/server2100/6p8lmnk/products/347/images/2292/standup_paddle_board_rack__43491.1392317669.225.360.jpg?c=2
[sort_order] => 20
[profitability] => 40
[last_google_update] => ActiveRecord\DateTime Object
*RECURSION*
[last_internal_update] =>
[discontinued] => 0
[stock_notes] =>
[deleted] => 0
[created_on] => ActiveRecord\DateTime Object
(
[model:ActiveRecord\DateTime:private] => Product Object
*RECURSION*
[attribute_name:ActiveRecord\DateTime:private] => created_on
[date] => 2014-03-25 22:31:58
[timezone_type] => 3
[timezone] => UTC
)
)
[__dirty:ActiveRecord\Model:private] => Array
(
)
[__readonly:ActiveRecord\Model:private] =>
[__relationships:ActiveRecord\Model:private] => Array
(
)
[__new_record:ActiveRecord\Model:private] =>
)
[attribute_name:ActiveRecord\DateTime:private] => last_google_update
[date] => 2014-05-21 05:01:12
[timezone_type] => 3
[timezone] => UTC
)
So the get the actual date, I tried this:
print_r($date->date);
However, this gives the following error:
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message: Undefined property: ActiveRecord\DateTime::$date</p>
<p>Filename: controllers/test.php</p>
<p>Line Number: 16</p>
</div>
But, if I include a call to get_active_vars() first, it works:
print_r(get_object_vars($date))
print_r($date->date);
Outputs:
Array
(
[date] => 2014-05-21 05:01:12
[timezone_type] => 3
[timezone] => UTC
)
2014-05-21 05:01:12
To summarize:
Are the *RECURSION* flags expected?
How do I work with datetime fields and how do I access the actual dates?
RECURSION is not good defenetly
I am not sure but
[model:ActiveRecord\DateTime:private] => Product Object
somehow you have product object in a dateTime so and class trying to parse it that is why recursion.
try to see configuration of the module
So solution is to use format function on the date object property.
$date->date->format('Y-m-d H:i:s')
PHP - Access MSSQL datetime column from the returned array
Array
(
[0] => Array
(
[CallId] => 45
[CallLoginId] => 1
[CustomerId] => 140
[CallOptionId] => 2
[CallTypeId] => 2
[CallStatusId] => 1
[CallDateTime] => DateTime Object
(
[date] => 2012-06-28 00:00:00
[timezone_type] => 3
[timezone] => Asia/Kolkata
)
[ContactNo] => 45151551115
[ContactPerson] => Contact Person name
[ProductId] => 1
[ProdCompanyId] => 1
[ProdCategoryId] => 1
[ModelNo] => 451212151
[ProdUnderId] => 1
[Problem] => Simple Problem Details
[Remarks] => Remarks
[Accessories] => Accessories
[CallCaseId] =>
[CallCaseDate] =>
[ServiceCharge] => 0
[CourierName] =>
[DocketNo] =>
[CompanyId] => 126
[ASPId] => 130
[InsBy] => 134
[InsDate] => DateTime Object
(
[date] => 2012-06-23 17:04:51
[timezone_type] => 3
[timezone] => Asia/Kolkata
)
[UpdBy] => 11
[UpdDate] => DateTime Object
(
[date] => 2012-06-28 18:29:23
[timezone_type] => 3
[timezone] => Asia/Kolkata
)
[FName] => Kumar
[MName] => a
[LName] => Customer
[ProductName] => LenovoDesktop420
[CallOption] => InHouse
[CallType] => H.W.Installation
[ProdCompany] => Lenovo
[ProdCategory] => Desktop
[ProdUnder] => AMC
[CallStatus] => Open
[EntityId] => 134
[InsertBy] => Bhavin Rana
)
)
how can access date time value form this returned array ?
thanks in advance.
You have an outer array with numerically indexed one element [0], which is an associative array. CallDateTime as a key of that array is a DateTime object.
$array[0]['CallDateTime']->format('Y-m-d H:i:s') // 2012-06-28 00:00:00
$array[0]['CallDateTime']->getTimezone()->getName() // Asia/Kolkata
// Same with InsDate and UpdDate
$array[0]['InsDate']->format('Y-m-d H:i:s') // 2012-06-23 17:04:51
$array[0]['InsDate']->getTimezone()->getName() // Asia/Kolkata