简体   繁体   中英

How can i surcharge a connection configuration from a controller in Lithium?

I'm building a GooglePlaces API, it is package as an http datasource.

I thought it would be a good idea to ship it with a basic Places model & a basic gplaces connection so that the datasource could be used out of the box in my app PlacesController using:

use app\models\Places;
use google\models\Places as GPlaces;

class PlacesController extends \lithium\action\Controller { ... }

But i'd like to be able to somehow surcharge the plugin default connection gplaces with so API key.

Tried:

GPlaces::config(array(
    'key' => '<private_api_key>'
));

But it does not affect (as we could expect) the Connection,

Any ideas?

In this instance, GPlaces is a model, so doing this is only going to assign that key to the model's configuration, which is not what you want.

If you have a connection called 'gplaces' , it should be configured with that key in Connections::add() , then you can tell your model to use that connection like so:

GPlaces::config(array(
    'connection' => 'gplaces'
));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM