2014-02-14 59 views
0

这里是我的核心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另一个类的对象,我必须采取由命名空间的名称和类的初始化新的新方法显示不存在的类错误。

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

    $this->library('client'); 

如何通过clientid和对象创建笨过程中的密钥,如果你会看到我的核心PHP代码我有一个新的运营商初始化对象,并传递价值,所以我们怎么能初始化类客户端和命名空间的对象在构造函数中传递值。

 } 
    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); 
     } 
     } 
     } 

回答

0

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

+0

我试过但错误不存在的类:客户 – user3306026

+0

这里是我更新的代码$ this-> load-> library('Client'); $ A = $ this-> client-> getAuthenticationUrl(AUTHORIZATION_ENDPOINT,REDIRECT_URI); \t echo $ a; – user3306026

+0

你的意思是说我们可以通过mvc库名直接运行,我们应如何修复类 – user3306026