我在codeigniter中的模型扩展后如何设置另一个模型(除了CI_Model之外)

时间:2012-12-14 22:17:41

标签: php codeigniter codeigniter-2

我想在我的“Adaptive_paypal_model”中扩展Paypal_class_model。 我写的时候

   class Adaptive_paypal_model extends Paypal_class_model
   {

此代码显示错误消息:

 Fatal error: Class 'Paypal_class_model' not found in C:\xampp\htdocs\business1\application\models\adaptive_paypal_model.php on line 3

请帮帮我

这是我想要包含的代码。请告诉我在php中包含文件的另一种方法

         class Paypal_class_model extends CI_Model
      {


     function Paypal_class_model()
         {

 $APIUsername = '';
 $APIPassword = '';
 $APISignature = '';
 $APISubject = '';
 $APIVersion = '';
$APIButtonSource = '';
 $APIMode = '';
 $EndPointURL = '';
        $Sandbox = '';
 $BetaSandbox = '';
 $PathToCertKeyPEM = '';
 $SSL = '';


function __construct($DataArray)
{       
    if(isset($DataArray['Sandbox']))
    {
        $this->Sandbox = $DataArray['Sandbox'];

    }
    elseif(isset($DataArray['BetaSandbox']))
    {
        $this->Sandbox = $DataArray['BetaSandbox'];
    }
    else
    {
        $this->Sandbox = true;
    }

    $this->Sandbox = isset($DataArray['Sandbox']) || isset($DataArray['BetaSandbox']) ? $DataArray['Sandbox'] : true;
    $this->BetaSandbox = isset($DataArray['BetaSandbox']) ? $DataArray['BetaSandbox'] : false;
    $this->APIVersion = isset($DataArray['APIVersion']) ? $DataArray['APIVersion'] : '95.0';
    $this->APIMode = isset($DataArray['APIMode']) ? $DataArray['APIMode'] : 'Signature';
    $this->APIButtonSource = 'AngellEYE_PHPClass';
    $this->PathToCertKeyPEM = '/path/to/cert/pem.txt';
    $this->SSL = $_SERVER['SERVER_PORT'] == '443' ? true : false;
    $this->APISubject = isset($DataArray['APISubject']) ? $DataArray['APISubject'] : '';

    if($this->Sandbox || $this->BetaSandbox)
    {
        // Show Errors
        error_reporting(E_ALL);
        ini_set('display_errors', '1');

        if($this->BetaSandbox)
        {
            # Beta Sandbox
            $this->APIUsername = isset($DataArray['APIUsername']) && $DataArray['APIUsername'] != '' ? $DataArray['APIUsername'] : '';
            $this->APIPassword = isset($DataArray['APIPassword']) && $DataArray['APIPassword'] != '' ? $DataArray['APIPassword'] : '';
            $this->APISignature = isset($DataArray['APISignature']) && $DataArray['APISignature'] != '' ? $DataArray['APISignature'] : '';
            $this->EndPointURL = isset($DataArray['EndPointURL']) && $DataArray['EndPointURL'] != '' ? $DataArray['EndPointURL'] : 'https://api-3t.beta-sandbox.paypal.com/nvp';    
        }
        else
        {
            # Sandbox
            $this->APIUsername = isset($DataArray['APIUsername']) && $DataArray['APIUsername'] != '' ? $DataArray['APIUsername'] : '';
            $this->APIPassword = isset($DataArray['APIPassword']) && $DataArray['APIPassword'] != '' ? $DataArray['APIPassword'] : '';
            $this->APISignature = isset($DataArray['APISignature']) && $DataArray['APISignature'] != '' ? $DataArray['APISignature'] : '';
            $this->EndPointURL = isset($DataArray['EndPointURL']) && $DataArray['EndPointURL'] != '' ? $DataArray['EndPointURL'] : 'https://api-3t.sandbox.paypal.com/nvp'; 
        }
    }
    else
    {
        $this->APIUsername = isset($DataArray['APIUsername']) && $DataArray['APIUsername'] != '' ? $DataArray['APIUsername'] : '';
        $this->APIPassword = isset($DataArray['APIPassword']) && $DataArray['APIPassword'] != '' ? $DataArray['APIPassword'] : '';
        $this->APISignature = isset($DataArray['APISignature']) && $DataArray['APISignature'] != '' ? $DataArray['APISignature'] : '';
        $this->EndPointURL = isset($DataArray['EndPointURL']) && $DataArray['EndPointURL'] != ''  ? $DataArray['EndPointURL'] : 'https://api-3t.paypal.com/nvp';
    }

    // Create the NVP credentials string which is required in all calls.
    $this->NVPCredentials = 'USER=' . $this->APIUsername . '&PWD=' . $this->APIPassword . '&VERSION=' . $this->APIVersion . '&BUTTONSOURCE=' . $this->APIButtonSource;
    $this->NVPCredentials .= $this->APISubject != '' ? '&SUBJECT=' . $this->APISubject : '';
    $this->NVPCredentials .= $this->APIMode == 'Signature' ? '&SIGNATURE=' . $this->APISignature : '';




} ?>

1 个答案:

答案 0 :(得分:0)

您可以自动加载模型,但可以在此处找到更好的解决方案:Extending Multiple models in Codeigniter 2 您可以节省每次通话中自动加载的开销。