Zend Framework 使用 application.ini 中的配置的正确命名约定

发布于 2024-09-16 12:35:36 字数 514 浏览 2 评论 0原文

我正在使用 Zend_Oauth_Consumer ,它需要传递许多配置值。目前我正在将一个数组传递到构造函数中,如下所示:

    $config = array(
        'callbackUrl' => 'http://www.domain.com/twitter/callback',
        'siteUrl' => 'http://twitter.com/oauth',
        'consumerKey' => 'XXXXXXXXXXXXXXXXXX',
        'consumerSecret' => 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'
        );
    $consumer = new Zend_Oauth_Consumer($config);

我不喜欢这种方法,因为这些配置现在位于控制器内,我希望它们像我的所有其他配置值一样位于 application.ini 中 - 我将如何解决这个问题?例如,是否有可遵循的命名约定?

I am using Zend_Oauth_Consumer which requires a number of config values to be passed. Currently i am passing an array into the constructor like so:

    $config = array(
        'callbackUrl' => 'http://www.domain.com/twitter/callback',
        'siteUrl' => 'http://twitter.com/oauth',
        'consumerKey' => 'XXXXXXXXXXXXXXXXXX',
        'consumerSecret' => 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'
        );
    $consumer = new Zend_Oauth_Consumer($config);

I dont like this approach as these configs are now within the controller and i would like them to be in application.ini like all my other configuration values - how would i go about this? is there a naming convention to follow for example?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只想待在家 2024-09-23 12:35:36

在你的 application.ini 中你可以这样做:

oauth_consumer.callbackUrl = "http://www.domain.com/twitter/callback"
oauth_consumer.siteUrl = "http://twitter.com/oauth"
oauth_consumer.consumerKey = "XXXXXXXXXXXXXXXXXX"
oauth_consumer.consumerSecret = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"

在你的控制器中:

$config = $this->getInvokeArg('bootstrap')->getOption('oauth_consumer');
$consumer = new Zend_Oauth_Consumer($config);

In your application.ini you can do this:

oauth_consumer.callbackUrl = "http://www.domain.com/twitter/callback"
oauth_consumer.siteUrl = "http://twitter.com/oauth"
oauth_consumer.consumerKey = "XXXXXXXXXXXXXXXXXX"
oauth_consumer.consumerSecret = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"

And in your controller:

$config = $this->getInvokeArg('bootstrap')->getOption('oauth_consumer');
$consumer = new Zend_Oauth_Consumer($config);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文