如何在Codeigniter中访问basecamp api以及在mvc中定义常量的位置

时间:2014-02-13 13:03:10

标签: php codeigniter

我尝试使用核心php的代码工作正常:

*以及在mvc.but中包含require语句的位置,而在使用Codeigniter时,浏览器中没有显示任何内容 Codeigniter的源代码

require_once('../libraries/client.php');
require_once('../libraries/GrantType/IGrantType.php');
require_once('../libraries/GrantType/AuthorizationCode.php');
class abc extends CI_Controller
{

  function __construct() {
    parent::__construct();
    $this->load->model('ea_model');
    $this->load->helper('url');
  }
  function index()
  {
    $data['abc']=$this->ea_model->ess_get();
    $this->load->view('e_view',$data);
  }
  function settoken()
  {
    const CLIENT_ID     = '******';
    const CLIENT_SECRET = '******';
    const REDIRECT_URI           = '*********';
    const AUTHORIZATION_ENDPOINT = 'https://launchpad.37signals.com/authorization/new';
    const TOKEN_ENDPOINT         = 'https://launchpad.37signals.com/authorizatio/token';
    $client = new OAuth2\Client(CLIENT_ID, CLIENT_SECRET);
   $auth_url = $client->getAuthenticationUrl(AUTHORIZATION_ENDPOINT,REDIRECT_URI);      

   //predifined function of class client//
    redirect($auth_url);//used to redirect the url //   

  } 
}
2. here is my client class our main goal is to   create object  of class client  which used access  basecamp  api through oath wrapper class client in codeinator.

         namespace OAuth2;

  class Client
    {




      }

1 个答案:

答案 0 :(得分:0)

您不应该像在控制器类之外那样使用require_once。而是在控制器方法/构造函数中使用CI的加载语法:

function __construct() {  // if you only use the libraries in the settoken() method I'd
                          // recommend you to add them only there
  parent::__construct();
  $this->load->library('client');
  $this->load->library('GrantType/IGrantType');  
  $this->load->library('GrantType/AuthorizationCode');
  $this->load->model('ea_model');
  $this->load->helper('url');
}
相关问题