我正在使用this oAuth库,这是FreeAgent推荐的(我正在加入的API)。
我的代码在独立文件中运行正常,但是当我的控制器中包含该代码时,我收到以下错误:
PHP Parse error: syntax error, unexpected T_CONST
在谷歌搜索10分钟后,我发现这个问题的唯一参考是由于使用PHP4,但我运行的是5.3.6,所以不是这样。它是范围/嵌套问题吗?
代码看起来大致如下:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Prop extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function testoauth()
{
require( site_url('oauth/client.php') );
require( site_url('oauth/GrantType/IGrantType.php') );
require( site_url('oauth/GrantType/AuthorizationCode.php') );
const CLIENT_ID = 'redacted';
...
错误是在const
的第一个实例上触发的。
编辑:好的,所以我澄清了constant
在函数中不存在。那么我到底怎么做CodeIgniter呢?我知道如何处理config
文件的唯一方法是与常量不兼容,而不是函数。
答案 0 :(得分:0)
这里需要做两件事。
第一个是问题@Ohgodwhy指出,常量不能存在于函数中。
事实证明,CodeIgniter在application/config/constants.php
所以他们最终看起来像这样,在该文件的底部:
/*
|--------------------------------------------------------------------------
| oAuth
|--------------------------------------------------------------------------
*/
define('CLIENT_ID', 'redacted');
...
其次我使用了site_url()
require
函数,这是不必要的,并导致了自己的新错误。