首页 > 解决方案 > 在codeiginter中读取配置文件中的数据库

问题描述

我正在通过此链接https://www.codexworld.com/paypal-payment-gateway-integration-in-codeigniter/集成贝宝。一切正常,完全没有问题。但我必须在 paypal 的配置文件中写入 paypal 的帐户电子邮件。我想给管理员选择,以便他可以更改贝宝帐户。我试图访问 cofing 文件中的数据库,但它给出了错误。paypal的配置文件如下

<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

// ------------------------------------------------------------------------
// Paypal library configuration
// ------------------------------------------------------------------------

 // PayPal environment, Sandbox or Live
 $config['sandbox'] = TRUE; // FALSE for live environment
 $paypal = $this->db->where('set_id',1)->get('settings')->row_array();
 // PayPal business email
 $config['business'] = $paypal['paypal_accnt'];

 // What is the default currency?
 $config['paypal_lib_currency_code'] = 'USD';

 // Where is the button located at?
 $config['paypal_lib_button_path'] = 'assets/images/';

 // If (and where) to log ipn response in a file
 $config['paypal_lib_ipn_log'] = TRUE;
 $config['paypal_lib_ipn_log_file'] = BASEPATH . 'logs/paypal_ipn.log';

我怎么能做到这一点。任何形式的帮助将不胜感激

标签: phpapicodeigniterpaypalconfig

解决方案


$this在控制器中工作以访问方法。我们不能$this在控制器类之外使用。所以使用

$CI =& get_instance();

$CI->load->helper('url');
$CI->load->library('session');
$CI->config->item('base_url');
// etc.

有用。有关更多详细信息,请访问user_guide


推荐阅读