Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

docs(backend): Add PHP backend example #401

Merged
merged 4 commits into from
May 25, 2017
Merged

Conversation

pixelastic
Copy link
Contributor

@pixelastic pixelastic commented May 16, 2017

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.

image

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.
@algobot
Copy link
Contributor

algobot commented May 16, 2017

Deploy preview ready!

Built with commit 80fb098

https://deploy-preview-401--algolia-places.netlify.com

$places = $client->initPlaces($appId, $apiKey);

$data = json_encode(array('query' => 'Paris'));
$result = $places->search($data);
Copy link
Member

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

Copy link
Contributor Author

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.

@raphi
Copy link
Contributor

raphi commented May 16, 2017

@rayrutjes any idea why it's not working without credentials? Def works using the REST API directly

@pixelastic
Copy link
Contributor Author

@raphi: I had an error trying to call initPlaces() without appId and apiKey. Same for instanciating the client.

@rayrutjes
Copy link
Member

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.

@vvo
Copy link
Contributor

vvo commented May 16, 2017

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();

@rayrutjes
Copy link
Member

@vvo your signature is the one I'm going for in the PHP Client. Gogogogo ;)

@raphi
Copy link
Contributor

raphi commented May 16, 2017

@rayrutjes but I think we need to update the php example committed here right?

@rayrutjes
Copy link
Member

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.

Copy link
Member

@rayrutjes rayrutjes left a 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.

@rayrutjes
Copy link
Member

rayrutjes commented May 22, 2017

@pixelastic I released the new PHP API Client (1.18.0) and updated the snippets accordingly.
Feel free to adjust from here ;)

Update: I did check the rendered value and it looks OK to me.

@raphi
Copy link
Contributor

raphi commented May 22, 2017

👍 LGTM thanks @rayrutjes !!

@raphi
Copy link
Contributor

raphi commented May 24, 2017

@pixelastic should we include examples for all our regular doc languages?

@pixelastic
Copy link
Contributor Author

pixelastic commented May 24, 2017 via email

@vvo
Copy link
Contributor

vvo commented May 24, 2017

I think only JavaScript and PHP are supported no? I will add one for JavaScript

@vvo vvo force-pushed the docs/backend-php-example branch from ffb0573 to 80fb098 Compare May 24, 2017 16:54
@vvo
Copy link
Contributor

vvo commented May 24, 2017

Changed a bit and added JS, good to merge I think

image



```js
// var algoliasearch = require('algoliasearch');
Copy link
Member

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?

Copy link
Contributor

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

@raphi raphi merged commit ec97f37 into master May 25, 2017
@raphi
Copy link
Contributor

raphi commented May 25, 2017

thanks guys

@raphi raphi deleted the docs/backend-php-example branch May 25, 2017 14:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants