[英]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.我正在构建一个 GooglePlaces API,它是 package 作为 http 数据源。
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:我认为将它与基本的
Places
model 和基本的gplaces
连接一起提供是个好主意,这样数据源就可以在我的应用程序PlacesController
中开箱即用地使用:
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.但我希望能够以某种方式使用 API 密钥对插件默认连接
gplaces
进行附加。
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.在这种情况下,
GPlaces
是 model,所以这样做只会将该键分配给模型的配置,这不是您想要的。
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'
的连接,则应使用Connections::add()
中的该键对其进行配置,然后您可以告诉 model 使用该连接,如下所示:
GPlaces::config(array(
'connection' => 'gplaces'
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.