Dear Brantree Developer(s) , I am trying to implement the braintree payments in my website and braintree has given Response in object of array with nested object How can i access it?. i want to get id of customer from bellow response.
Braintree_Result_Successful Object
(
[success] => 1
[_returnObjectNames:private] => Array
(
[0] => customer
)
[_attributes] => Array
(
)
[customer] => Braintree_Customer Object
(
[_attributes:protected] => Array
(
[id] => 22635830
[merchantId] => h9xhpt9b5zjgbkpj
[firstName] => Abhishek
[lastName] => Sonawane
[company] => 1
[email] => abhishek#iarianatech.com
[phone] =>
[fax] =>
[website] =>
[createdAt] => DateTime Object
(
)
[updatedAt] => DateTime Object
(
)
[customFields] =>
[creditCards] => Array
(
[0] => Braintree_CreditCard Object
(
[_attributes] => Array
(
[bin] => 510510
[expirationMonth] => 12
[expirationYear] => 2015
[last4] => 5100
[cardType] => MasterCard
[cardholderName] =>
[commercial] => Unknown
[countryOfIssuance] => Unknown
[createdAt] => DateTime Object
(
)
[customerId] => 22635830
[customerLocation] => US
[debit] => Unknown
[default] => 1
[durbinRegulated] => Unknown
[expired] =>
[healthcare] => Unknown
[imageUrl] => https://assets.braintreegateway.com/payment_method_logo/mastercard.png?environment=sandbox
[issuingBank] => Unknown
[payroll] => Unknown
[prepaid] => Unknown
[subscriptions] => Array
(
)
[token] => 6k2mk2
[uniqueNumberIdentifier] => 0ec6bdfe18781d1bccaea74c4fe55897
[updatedAt] => DateTime Object
(
)
[venmoSdk] =>
[verifications] => Array
(
)
[billingAddress] =>
[expirationDate] => 12/2015
[maskedNumber] => 510510******5100
)
)
)
[addresses] => Array
(
)
[coinbaseAccounts] => Array
(
)
[paypalAccounts] => Array
(
)
[applePayCards] => Array
(
)
)
)
)
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
It looks like that response is coming from a Customer create call. To specifically retrieve the id -
$result = Braintree_Customer::create([
'firstName' => 'Mike',
'lastName' => 'Jones',
'company' => 'Jones Co.',
'email' => 'mike.jones#example.com',
'phone' => '281.330.8004',
'fax' => '419.555.1235',
'website' => 'http://example.com'
]);
$result->success;
# true
$id = $result->customer->id;
Check the API Response section of the guides for getting other attributes.
Related
I just started learning how to use the GitHub API. I wrote a sample program, to list my repositories. I have 5 repos, and I am only getting one. Any ideas?
My code:
<? php
DEFINE ('PERSONAL_TOKEN', 'xxxxxxxxxxxxxxxxx');
$headers = [
'Accept: application/vnd.github.v3+json',
'User-Agent: Some Text',
'Authorization: token '. PERSONAL_TOKEN
];
$res = list_repositories($headers);
print "<pre>";
print_r($res);
print "</pre>";
function list_repositories($headers)
{
$curl_url = GITHUB_REST_URL.'myusernameful'.'/repos';
$ch = curl_init($curl_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$res = json_decode(curl_exec($ch), TRUE);
curl_close($ch);
return $output;
}
I was expecting to get all 5 of my repos, instead, I am only getting one back:
Array
(
[0] => Array
(
[id] => 168594503
[node_id] => MDEwOlJlcG9zaXRvcnkxNjg1OTQ1MDM=
[name] => repo_one
[full_name] => myusername/repo_one
[private] =>
[owner] => Array
(
[login] => myusername
[id] => 45577729
[node_id] => MDQ6VXNlcjQ1NTc3NzI5
[avatar_url] => https://avatars1.githubusercontent.com/u/45577729?v=4
[gravatar_id] =>
[url] => https://api.github.com/users/myusername
[html_url] => https://github.com/myusername
[followers_url] => https://api.github.com/users/myusername/followers
[following_url] => https://api.github.com/users/myusername/following{/other_user}
[gists_url] => https://api.github.com/users/myusername/gists{/gist_id}
[starred_url] => https://api.github.com/users/myusername/starred{/owner}{/repo}
[subscriptions_url] => https://api.github.com/users/myusername/subscriptions
[organizations_url] => https://api.github.com/users/myusername/orgs
[repos_url] => https://api.github.com/users/myusername/repos
[events_url] => https://api.github.com/users/myusername/events{/privacy}
[received_events_url] => https://api.github.com/users/myusername/received_events
[type] => User
[site_admin] =>
)
[html_url] => https://github.com/myusername/repo_one
[description] => repo_one makes it easy and fast to build beautiful mobile apps.
[fork] => 1
[url] => https://api.github.com/repos/myusername/repo_one
[forks_url] => https://api.github.com/repos/myusername/repo_one/forks
[keys_url] => https://api.github.com/repos/myusername/repo_one/keys{/key_id}
[collaborators_url] => https://api.github.com/repos/myusername/repo_one/collaborators{/collaborator}
[teams_url] => https://api.github.com/repos/myusername/repo_one/teams
[hooks_url] => https://api.github.com/repos/myusername/repo_one/hooks
[issue_events_url] => https://api.github.com/repos/myusername/repo_one/issues/events{/number}
[events_url] => https://api.github.com/repos/myusername/repo_one/events
[assignees_url] => https://api.github.com/repos/myusername/repo_one/assignees{/user}
[branches_url] => https://api.github.com/repos/myusername/repo_one/branches{/branch}
[tags_url] => https://api.github.com/repos/myusername/repo_one/tags
[blobs_url] => https://api.github.com/repos/myusername/repo_one/git/blobs{/sha}
[git_tags_url] => https://api.github.com/repos/myusername/repo_one/git/tags{/sha}
[git_refs_url] => https://api.github.com/repos/myusername/repo_one/git/refs{/sha}
[trees_url] => https://api.github.com/repos/myusername/repo_one/git/trees{/sha}
[statuses_url] => https://api.github.com/repos/myusername/repo_one/statuses/{sha}
[languages_url] => https://api.github.com/repos/myusername/repo_one/languages
[stargazers_url] => https://api.github.com/repos/myusername/repo_one/stargazers
[contributors_url] => https://api.github.com/repos/myusername/repo_one/contributors
[subscribers_url] => https://api.github.com/repos/myusername/repo_one/subscribers
[subscription_url] => https://api.github.com/repos/myusername/repo_one/subscription
[commits_url] => https://api.github.com/repos/myusername/repo_one/commits{/sha}
[git_commits_url] => https://api.github.com/repos/myusername/repo_one/git/commits{/sha}
[comments_url] => https://api.github.com/repos/myusername/repo_one/comments{/number}
[issue_comment_url] => https://api.github.com/repos/myusername/repo_one/issues/comments{/number}
[contents_url] => https://api.github.com/repos/myusername/repo_one/contents/{+path}
[compare_url] => https://api.github.com/repos/myusername/repo_one/compare/{base}...{head}
[merges_url] => https://api.github.com/repos/myusername/repo_one/merges
[archive_url] => https://api.github.com/repos/myusername/repo_one/{archive_format}{/ref}
[downloads_url] => https://api.github.com/repos/myusername/repo_one/downloads
[issues_url] => https://api.github.com/repos/myusername/repo_one/issues{/number}
[pulls_url] => https://api.github.com/repos/myusername/repo_one/pulls{/number}
[milestones_url] => https://api.github.com/repos/myusername/repo_one/milestones{/number}
[notifications_url] => https://api.github.com/repos/myusername/repo_one/notifications{?since,all,participating}
[labels_url] => https://api.github.com/repos/myusername/repo_one/labels{/name}
[releases_url] => https://api.github.com/repos/myusername/repo_one/releases{/id}
[deployments_url] => https://api.github.com/repos/myusername/repo_one/deployments
[created_at] => 2019-01-31T20:50:56Z
[updated_at] => 2019-02-01T22:17:23Z
[pushed_at] => 2019-01-31T20:48:11Z
[git_url] => git://github.com/myusername/repo_one.git
[ssh_url] => git#github.com:myusername/repo_one.git
[clone_url] => https://github.com/myusername/repo_one.git
[svn_url] => https://github.com/myusername/repo_one
[homepage] => https://repo_one.io
[size] => 52581
[stargazers_count] => 0
[watchers_count] => 0
[language] => Dart
[has_issues] =>
[has_projects] => 1
[has_downloads] => 1
[has_wiki] => 1
[has_pages] =>
[forks_count] => 0
[mirror_url] =>
[archived] =>
[open_issues_count] => 0
[license] => Array
(
[key] => other
[name] => Other
[spdx_id] => NOASSERTION
[url] =>
[node_id] => MDc6TGljZW5zZTA=
)
[forks] => 0
[open_issues] => 0
[watchers] => 0
[default_branch] => master
[permissions] => Array
(
[admin] => 1
[push] => 1
[pull] => 1
)
)
)
The "List your Repositories" is /user/repos, not /users/:username/repos.
If you use your GitHub username in the URL (as in the latter case), you would get only your public repositories, not all your repos (public and private)
I have created a new module to add a new step to the signup process to get the user's phone number. Everything works fine, except the fact that after the signup, I need to grab the phone number I have received in my specific step and add it to the users table. For this purpose, I have added a hook in my module's manifest file as follows to be triggered after signup completes:
<?php
return array(
'package' =>
array(
'type' => 'module',
'name' => 'advancedsmsplugin',
'version' => '4.0.0',
'sku' => 'com.company.sms',
'path' => 'application/modules/Advancedsmsplugin',
'title' => 'Advanced SMS Plugin',
'description' => 'Advanced SMS Plugin',
'author' => 'Company Ltd.',
'callback' =>
array(
'class' => 'Engine_Package_Installer_Module',
),
'actions' =>
array(
0 => 'install',
1 => 'upgrade',
2 => 'refresh',
3 => 'enable',
4 => 'disable',
),
'directories' =>
array(
0 => 'application/modules/Advancedsmsplugin',
),
'files' =>
array(
0 => 'application/languages/en/advancedsmsplugin.csv',
1 => 'application/modules/User/Form/Signup/Phone.php',
2 => 'application/modules/User/Plugin/Signup/Phone.php',
),
),
'hooks' => array(
array(
'event' => 'onUserCreateAfter',
'resource' => 'User_Plugin_Phone',
),
),
);
?>
I have also created the class that I named in the hook namely User_Plugin_Phone and saved it as application/modules/user/Plugin/Phone.php.
class User_Plugin_Phone extends Core_Plugin_Abstract {
public function onUserCreateAfter($event) {
echo '<script>console.log("Inside User_Plugin_Phone::onUserCreateAfter");</script>';
echo '<script>alert("Inside User_Plugin_Phone: onUserCreateAfter");</script>';
$payload = $event->getPayload();
}
}
But, logs show that the hook is not triggered at all. I have checked this and this, and I think I have followed them correctly. Any ideas why this does not work]?
I am trying to make request to OneDrive, but so far no success. I have been able to obtain access token that I think is good because I can access informations from https://graph.microsoft.com/v1.0/me. But when I try to access https://graph.microsoft.com/v1.0/me/drive I get 500 error response, this is what response object says:
[message:protected] => Unable to resolve template token
[string:Exception:private] =>
[code:protected] => 500
[file:protected] => C:\xampp\htdocs\OneDrive\vendor\thenetworg\oauth2-azure\src\Provider\Azure.php
[line:protected] => 68
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => C:\xampp\htdocs\OneDrive\vendor\league\oauth2-client\src\Provider\AbstractProvider.php
[line] => 644
[function] => checkResponse
[class] => TheNetworg\OAuth2\Client\Provider\Azure
[type] => ->
[args] => Array
(
[0] => GuzzleHttp\Psr7\Response Object
(
[reasonPhrase:GuzzleHttp\Psr7\Response:private] => Internal Server Error
[statusCode:GuzzleHttp\Psr7\Response:private] => 500
[headers:GuzzleHttp\Psr7\Response:private] => Array
(
[Cache-Control] => Array
(
[0] => private
)
[Transfer-Encoding] => Array
(
[0] => chunked
)
[Content-Type] => Array
(
[0] => application/json
)
[request-id] => Array
(
[0] => 7fc5c1c8-bd33-4788-bae9-5887d261c8c5
)
[client-request-id] => Array
(
[0] => 7fc5c1c8-bd33-4788-bae9-5887d261c8c5
)
[x-ms-ags-diagnostic] => Array
(
[0] => {"ServerInfo":{"DataCenter":"West Europe","Slice":"SliceB","ScaleUnit":"003","Host":"AGSFE_IN_2","ADSiteName":"AMS"}}
)
[Duration] => Array
(
[0] => 177.0851
)
[Date] => Array
(
[0] => Mon, 06 Feb 2017 12:55:27 GMT
)
)
[headerNames:GuzzleHttp\Psr7\Response:private] => Array
(
[cache-control] => Cache-Control
[transfer-encoding] => Transfer-Encoding
[content-type] => Content-Type
[request-id] => request-id
[client-request-id] => client-request-id
[x-ms-ags-diagnostic] => x-ms-ags-diagnostic
[duration] => Duration
[date] => Date
)
[protocol:GuzzleHttp\Psr7\Response:private] => 1.1
[stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object
(
[stream:GuzzleHttp\Psr7\Stream:private] => Resource id #79
[size:GuzzleHttp\Psr7\Stream:private] => 237
[seekable:GuzzleHttp\Psr7\Stream:private] => 1
[readable:GuzzleHttp\Psr7\Stream:private] => 1
[writable:GuzzleHttp\Psr7\Stream:private] => 1
[uri:GuzzleHttp\Psr7\Stream:private] => php://temp
[customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
(
)
)
)
[1] => Array
(
[error] => Array
(
[code] => InternalServerError
[message] => Unable to resolve template token
[innerError] => Array
(
[request-id] => 7fc5c1c8-bd33-4788-bae9-5887d261c8c5
[date] => 2017-02-06T12:55:28
)
)
)
)
)
Problem was that I was using thephpleague/oauth2 package that is recommended by official docs. Links to token and authorize URL were not to the v2.0 endpoint.
I am trying to get response from
https://graph.microsoft.com/v1.0/me/drive
but so far all I am getting is exception
Uncaught exception 'League\OAuth2\Client\Provider\Exception\IdentityProviderException' with message 'Unable to resolve template token'
I am using this Azure Active Directory oauth2 library that was recommended in documentation.
After obtaining access token I try to call
$this->provider->get('https://graph.microsoft.com/v1.0/me/drive',$_SESSION['access_token']); but that only throw exception. If I use
$this->provider->get('https://graph.microsoft.com/v1.0/me',$_SESSION['access_token']);
It returns informations about user account.
This is the error message that I am getting.
[message:protected] => Unable to resolve template token
[string:Exception:private] =>
[code:protected] => 500
[file:protected] => C:\xampp\htdocs\OneDrive\vendor\thenetworg\oauth2-azure\src\Provider\Azure.php
[line:protected] => 68
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => C:\xampp\htdocs\OneDrive\vendor\league\oauth2-client\src\Provider\AbstractProvider.php
[line] => 644
[function] => checkResponse
[class] => TheNetworg\OAuth2\Client\Provider\Azure
[type] => ->
[args] => Array
(
[0] => GuzzleHttp\Psr7\Response Object
(
[reasonPhrase:GuzzleHttp\Psr7\Response:private] => Internal Server Error
[statusCode:GuzzleHttp\Psr7\Response:private] => 500
[headers:GuzzleHttp\Psr7\Response:private] => Array
(
[Cache-Control] => Array
(
[0] => private
)
[Transfer-Encoding] => Array
(
[0] => chunked
)
[Content-Type] => Array
(
[0] => application/json
)
[request-id] => Array
(
[0] => 7fc5c1c8-bd33-4788-bae9-5887d261c8c5
)
[client-request-id] => Array
(
[0] => 7fc5c1c8-bd33-4788-bae9-5887d261c8c5
)
[x-ms-ags-diagnostic] => Array
(
[0] => {"ServerInfo":{"DataCenter":"West Europe","Slice":"SliceB","ScaleUnit":"003","Host":"AGSFE_IN_2","ADSiteName":"AMS"}}
)
[Duration] => Array
(
[0] => 177.0851
)
[Date] => Array
(
[0] => Mon, 06 Feb 2017 12:55:27 GMT
)
)
[headerNames:GuzzleHttp\Psr7\Response:private] => Array
(
[cache-control] => Cache-Control
[transfer-encoding] => Transfer-Encoding
[content-type] => Content-Type
[request-id] => request-id
[client-request-id] => client-request-id
[x-ms-ags-diagnostic] => x-ms-ags-diagnostic
[duration] => Duration
[date] => Date
)
[protocol:GuzzleHttp\Psr7\Response:private] => 1.1
[stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object
(
[stream:GuzzleHttp\Psr7\Stream:private] => Resource id #79
[size:GuzzleHttp\Psr7\Stream:private] => 237
[seekable:GuzzleHttp\Psr7\Stream:private] => 1
[readable:GuzzleHttp\Psr7\Stream:private] => 1
[writable:GuzzleHttp\Psr7\Stream:private] => 1
[uri:GuzzleHttp\Psr7\Stream:private] => php://temp
[customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
(
)
)
)
[1] => Array
(
[error] => Array
(
[code] => InternalServerError
[message] => Unable to resolve template token
[innerError] => Array
(
[request-id] => 7fc5c1c8-bd33-4788-bae9-5887d261c8c5
[date] => 2017-02-06T12:55:28
)
)
)
)
)
So it returns status code 500 which probably means that error is on their side. But If I try to access https://graph.microsoft.com/v1.0/me/drive through https://graph.microsoft.io/en-us/graph-explorer then I get normal response.
Also one thing I noticed is that I cannot change permission of access token. I tried to change it in Application registration portal, and also in my code I set scopes, but my token has always same permission [scope] => Files.ReadWrite User.Read
EDIT:
Here is what my request object looks like
GuzzleHttp\Psr7\Request Object
(
[method:GuzzleHttp\Psr7\Request:private] => GET
[requestTarget:GuzzleHttp\Psr7\Request:private] =>
[uri:GuzzleHttp\Psr7\Request:private] => GuzzleHttp\Psr7\Uri Object
(
[scheme:GuzzleHttp\Psr7\Uri:private] => https
[userInfo:GuzzleHttp\Psr7\Uri:private] =>
[host:GuzzleHttp\Psr7\Uri:private] => graph.microsoft.com
[port:GuzzleHttp\Psr7\Uri:private] =>
[path:GuzzleHttp\Psr7\Uri:private] => /v1.0/me/drive
[query:GuzzleHttp\Psr7\Uri:private] =>
[fragment:GuzzleHttp\Psr7\Uri:private] =>
)
[headers:GuzzleHttp\Psr7\Request:private] => Array
(
[Host] => Array
(
[0] => graph.microsoft.com
)
[Authorization] => Array
(
[0] => Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI6IkFRQUJBQUFBQUFEUk5ZUlEzZGhSU3JtLTRLLWFkcENKbFFSTFVXOUFERTZ0X0FwV0JuMGZNSTFUbC1Mb3ZFanBSaURnNU5laEFMTVgzbkU3U18xRkNWc2pwM19scEZoekNUSTZLbnkxN01ybFg0RGpRNHVwQUNBQSIsImFsZyI6IlJTMjU2IiwieDV0IjoiWTR1ZUsyb2FJTlFpUWI1WUVCU1lWeURjcEFVIiwia2lkIjoiWTR1ZUsyb2FJTlFpUWI1WUVCU1lWeURjcEFVIn0.eyJhdWQiOiJodHRwczovL2dyYXBoLm1pY3Jvc29mdC5jb20vIiwiaXNzIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvOTE4ODA0MGQtNmM2Ny00YzViLWIxMTItMzZhMzA0YjY2ZGFkLyIsImlhdCI6MTQ4NjQ1ODk1MiwibmJmIjoxNDg2NDU4OTUyLCJleHAiOjE0ODY0NjI4NTIsImFjciI6IjEiLCJhaW8iOiJBUUFCQUFFQUFBRFJOWVJRM2RoUlNybS00Sy1hZHBDSmxsbjlqVi11Wl9qOVlwYUltZ04zbEZ3cEUxUlp5QkNJelhmWkltdWtZSmJNSlZfWWp0d05vc3JMalA1c0JoWnY0QVFvVWNXNnF6MVBRTVF1LUJ5bVBZb0hjTTVGMHd3MW90WFJsUGpaUlAwRVFGeld5MXJTWmRCNXJSLVR5MjZWc2dLWWFNTVJRQlVDQ1VOaDM0SjN6aUFBIiwiYWx0c2VjaWQiOiIxOmxpdmUuY29tOjAwMDMwMDAwQzVERTc2MjkiLCJhbXIiOlsicHdkIl0sImFwcF9kaXNwbGF5bmFtZSI6Ik9uZURVcGxvYWQiLCJhcHBpZCI6IjE2NzdlZTQ4LTMwMGItNDVlNy1hYmQ5LTliNzE5YjkyNTBkMiIsImFwcGlkYWNyIjoiMSIsImVtYWlsIjoibWFydGluaG9uemExMjNAZ21haWwuY29tIiwiZmFtaWx5X25hbWUiOiJIb256YSIsImdpdmVuX25hbWUiOiJNYXJ0aW4iLCJpZHAiOiJsaXZlLmNvbSIsImlwYWRkciI6IjgxLjE5LjguNTgiLCJuYW1lIjoiTWFydGluIEhvbnphIiwib2lkIjoiYmIxOWIzZWMtMDJkZC00YjZkLWI0YmEtNGVjM2I5YjU1MDgyIiwicGxhdGYiOiIzIiwicHVpZCI6IjEwMDMwMDAwQzVERTc2MjkiLCJzY3AiOiJGaWxlcy5SZWFkIEZpbGVzLlJlYWRXcml0ZSBGaWxlcy5SZWFkV3JpdGUuQWxsIiwic3ViIjoiRGRxU1E5ckJBZVNpSTJlN1cyNmJucnVrSDZfTjlhdDR2SEJUYk1TVTh5ayIsInRpZCI6IjkxODgwNDBkLTZjNjctNGM1Yi1iMTEyLTM2YTMwNGI2NmRhZCIsInVuaXF1ZV9uYW1lIjoibGl2ZS5jb20jbWFydGluaG9uemExMjNAZ21haWwuY29tIiwidmVyIjoiMS4wIn0.R4KqgeI42iGjIBoeHGnUQ7Hq519kg0cPeymNsY0JoWmwd638W8MHtYqWZh4f_Yqb45SkznrypXzZPfWOdLL1QdTXhE_eItVnjdo9dS6Q-aX9DOxGo-kZONi1tWSUukpkiVafQLyEsles3uGi2QEkila1P73hPGAuCORkwPEMolLQwr33G1KSAZpB0OnvhTfghNt82_abpFiq14b5QXvrDgEQvtTtAqVZke-kOwOGTy4FJ9y50ZQ0rij9StRBq1CvVCJlcEcUZay5dRYfrLrdt8Wr-NLt1NGVayxWQ8Zlp68o7RXZ1nrGWAyLJ9ReQsP0ToCzJU2RP8n9U_batLSqew
)
)
[headerNames:GuzzleHttp\Psr7\Request:private] => Array
(
[authorization] => Authorization
[host] => Host
)
[protocol:GuzzleHttp\Psr7\Request:private] => 1.1
[stream:GuzzleHttp\Psr7\Request:private] =>
)
The token needs to be supplied in the request header via the Authorization property. Note that you must prepend "Bearer " to the token in the header.
Authorization: Bearer <token>
Update:
If you've change the scopes defined in Active Directory, you will also need to have the user re-consent to the new scopes. To force this, include prompt=consent in your query string.
I am using tableRegistry::get() and that returns the query object. I want only data of the table which is return by find() function in CakePHP2.X version. For that I need to use "hydrate" as I read in one of the suggestion. Here is my code:
public function beforeFilter(Event $event){
$this->maincategories();
}
function maincategories(){
$postcategories = TableRegistry::get('Postcategories',[
'className' => 'App\Model\Table\PostcategoriesTable',
'table' => 'postcategories'
]);
$query = $postcategories->find('all',['fields'=>[
'Postcategory.id',
'Postcategory.name'
], 'contain' => ['']])->hydrate(false)->toArray();
pr($query);exit;
}
This code is still giving me the error "Postcategories is not associated with"
remove the empty contain
$query = $postcategories->find('all')
->select(['Postcategory.id', 'Postcategory.name'])
->hydrate(false)
->toArray();
I am using "threaded" for find query
Array
(
[0] => Array
(
[id] => 1
[parent_id] =>
[name] => Web Development
[active] => 1
[lft] => 1
[rght] => 6
[created] => Cake\I18n\Time Object
(
[date] => 2015-02-10 14:11:19.000000
[timezone_type] => 3
[timezone] => UTC
)
[modified] => Cake\I18n\Time Object
(
[date] => 2015-02-10 14:11:19.000000
[timezone_type] => 3
[timezone] => UTC
)
[children] => Array
(
[0] => Array
(
[id] => 2
[parent_id] => 1
[name] => Open Source
[active] => 1
[lft] => 2
[rght] => 5
[created] => Cake\I18n\Time Object
(
[date] => 2015-02-10 14:11:54.000000
[timezone_type] => 3
[timezone] => UTC
)
[modified] => Cake\I18n\Time Object
(
[date] => 2015-02-10 14:11:54.000000
[timezone_type] => 3
[timezone] => UTC
)
[children] => Array
(
[0] => Array
(
[id] => 3
[parent_id] => 2
[name] => PHP
[active] => 1
[lft] => 3
[rght] => 4
[created] => Cake\I18n\Time Object
(
[date] => 2015-02-10 15:57:11.000000
[timezone_type] => 3
[timezone] => UTC
)
[modified] => Cake\I18n\Time Object
(
[date] => 2015-02-10 15:57:11.000000
[timezone_type] => 3
[timezone] => UTC
)
[children] => Array
(
)
)
)
)
)
)
[1] => Array
(
[id] => 4
[parent_id] =>
[name] => Technology
[active] => 1
[lft] => 7
[rght] => 8
[created] => Cake\I18n\Time Object
(
[date] => 2015-02-11 11:26:22.000000
[timezone_type] => 3
[timezone] => UTC
)
[modified] => Cake\I18n\Time Object
(
[date] => 2015-02-11 11:26:22.000000
[timezone_type] => 3
[timezone] => UTC
)
[children] => Array
(
)
)
[2] => Array
(
[id] => 5
[parent_id] =>
[name] => Frameworks
[active] => 1
[lft] => 9
[rght] => 10
[created] => Cake\I18n\Time Object
(
[date] => 2015-06-19 16:24:24.000000
[timezone_type] => 3
[timezone] => UTC
)
[modified] => Cake\I18n\Time Object
(
[date] => 2015-06-19 16:24:24.000000
[timezone_type] => 3
[timezone] => UTC
)
[children] => Array
(
)
)
)