如何在codeigniter中创建类的对象

时间:2014-02-14 11:22:10

标签: php codeigniter

这是我的核心PHP代码:

require('common/Client.php');              // include php wrapper  class
require('common/GrantType/IGrantType.php');// include php wrapper  class//
require('common/GrantType/AuthorizationCode.php'); // include php wrapper  class//
const CLIENT_ID     = '***********'; //generated from base_camp api//
const CLIENT_SECRET ='***********'; 
const REDIRECT_URI           = '***********';
const AUTHORIZATION_ENDPOINT = 'https://launchpad.37signals.com/authorization/new';
const TOKEN_ENDPOINT         = 'https://launchpad.37signals.com/authorization/token';

     session_start();

$client = new OAuth2\my_class(CLIENT_ID, CLIENT_SECRET);
if (!isset($_GET['code']))
 {
   $_SESSION['org'] = $_GET['org'];
  $auth_url = $client->getAuthenticationUrl(AUTHORIZATION_ENDPOINT, REDIRECT_URI);
  header('Location: ' . $auth_url);
  die('Redirect');
    }
   else
  {
    $params = array( 'type' => 'web_server', 'client_id' => CLIENT_ID, 'redirect_uri' => REDIRECT_URI, 'client_secret' => CLIENT_SECRET, 'code' => $_GET['code']);
 $response = $client->getAccessToken(TOKEN_ENDPOINT, 'authorization_code', $params);

$client->setAccessToken($response['result']['access_token']);

 $org = $_SESSION['org'].'_ess';
 mysql_connect('localhost','root','*******') or die('Cannot connect to database !');
 mysql_select_db($org) or die('No database found in mysql !');

$gcntct = mysql_query("select * from e_users");
}

如何在mvc中初始化另一个类的对象,我已经采用new方法初始化new命名空间名称和类显示不存在的类错误。

    oath2 is namespace and client is library class name.
    function a()
    {

   $this->library('client');

如何在对象创建codeigniter期间传递clientid和密钥,好像你会看到我的核心php代码我用new运算符初始化对象并传递值,那么我们怎样才能初始化类客户端和命名空间的对象在构造函数中传递值。

       } 
     client.php lib
     namesapce oath2
     class client
     {

  public function __construct($client_id, $client_secret, $client_auth =          self::AUTH_TYPE_URI, $certificate_file = null)
         {
     if (!extension_loaded('curl')) {
         throw new Exception('The PHP extention curl must be installed to use this library.', Exception::CURL_NOT_FOUND);
      }

     $this->client_id     = $client_id;
     $this->client_secret = $client_secret;
     $this->client_auth   = $client_auth;
     $this->certificate_file = $certificate_file;
     if (!empty($this->certificate_file)  && !is_file($this->certificate_file)) {
        throw new InvalidArgumentException('The certificate file was not found', InvalidArgumentException::CERTIFICATE_NOT_FOUND);
      }
      }
      }

1 个答案:

答案 0 :(得分:0)

在Codeigniter中创建一个库并加载它。 See herehere