-
Notifications
You must be signed in to change notification settings - Fork 234
docs(backend): Add PHP backend example #401
Conversation
This adds a code example on how to use initPlaces() with the PHP API Client to do a Places call. I think it only works with registered account, I could not make it work without credentials.
Deploy preview ready! Built with commit 80fb098 |
$places = $client->initPlaces($appId, $apiKey); | ||
|
||
$data = json_encode(array('query' => 'Paris')); | ||
$result = $places->search($data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this has to be called like:
$places->search($query);
No need for the json_encode.
See: https://github.com/algolia/algoliasearch-client-php/blob/master/src/AlgoliaSearch/Index.php#L507
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, just pushed a simplification.
@rayrutjes any idea why it's not working without credentials? Def works using the REST API directly |
@raphi: I had an error trying to call |
So we just tested it with @raphi , here is the code: // Without credentials.
$places = \AlgoliaSearch\Client::initPlaces();
$results = $places->search('Paris');
var_dump($results);
// With credentials.
$places = \AlgoliaSearch\Client::initPlaces($appId, $apiKey);
$results = $places->search('Paris');
var_dump($results); Beware that the credential-less solution needs a fix in the client to work because currently it does scream when no credentials are provided. |
Are we good on the php example? I would also like to add a JavaScript one (I thought we had it already): var algoliasearch = require('algoliasearch');
var places = algoliasearch.initPlaces(/*appId, apiKey*/);
places.search(); |
@vvo your signature is the one I'm going for in the PHP Client. Gogogogo ;) |
@rayrutjes but I think we need to update the php example committed here right? |
Yes, this should not be merged yet. I'm about to PR the support of the different snippets I shared. Let's wait until that is merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to refactor the PHP examples.
Then we need to wait for PR to support empty credentials.
Should be OK in a few.
@pixelastic I released the new PHP API Client (1.18.0) and updated the snippets accordingly. Update: I did check the rendered value and it looks OK to me. |
👍 LGTM thanks @rayrutjes !! |
@pixelastic should we include examples for all our regular doc languages? |
That would be awesome I'd say. But I'm 'it sure all the API Client allow instantiating a Places account.
On Wed, May 24, 2017 at 10:16am, raphi < notifications@github.com [notifications@github.com] > wrote:
@pixelastic [https://github.com/pixelastic] should we include examples for all our regular doc languages?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub [#401 (comment)] , or mute the thread [https://github.com/notifications/unsubscribe-auth/AARTG1c3yj7Nevced6-x10_0AtLapOHKks5r8-d0gaJpZM4NcVeg] .
|
I think only JavaScript and PHP are supported no? I will add one for JavaScript |
ffb0573
to
80fb098
Compare
|
||
|
||
```js | ||
// var algoliasearch = require('algoliasearch'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this line commented out on purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but maybe not obvious why: client can be used in nodejs,browser with npm or scripts
thanks guys |
This adds a code example on how to use initPlaces() with the PHP API
Client to do a Places call. I think it only works with registered
account, I could not make it work without credentials.