PHP类使我无法访问所需的变量

时间:2010-08-09 21:30:44

标签: php

好吧所以我有一个php文件,其中包含用于执行sql插入的代码

myfile.php

include($somewhere.'/addleads.php');

addleads.php

require_once(MAIN_CLASS_PATH."common/class.Common.php");
require_once(MAIN_CLASS_PATH."modules/Leads/class.Leads.php");
$objcommon    = new common();
$objLeads     = new Leads();
$Errormsg = $objLeads->AddLBCleads($_REQUEST);

class.Leads.php

class Leads extends Common{

function Leads(){
    $this->Common();
    $this->Leadstype        = "Leadstype";
    $this->Leads            = "Leads";


}

function AddLBCleads($objArray){

    global $_REQUEST,$objSmarty,$global_config;
    $objLeads = new Leads();
    $objInsertArray['txtP_Ident']       = $objArray['selProperty'];
    $objInsertArray['txtFirstName']     = $objArray['txtfirstname'];
    $objInsertArray['txtLastName']      = $objArray['txtlastname'];
    $objInsertArray['txtEmail']         = $objArray['txtEmail'];
    $objInsertArray['txtPhone']         = $objArray['txtPhone'];
    $objInsertArray['txtTypeId']        = $objArray['selleadtype'];
    $objInsertArray['txtComments']      = $objArray['txtcomments']; 
    $StrEnterdate                       = date('Y-m-d H:i:s');
    $objInsertArray['txtMoveDate']      = $StrMoveDate;
    $objInsertArray['txtEntereddate']   = $StrEnterdate;

    $current_id = $this->AddInfoToDB($objInsertArray,"txt",$this->LBCPrimary_leads);

当我尝试访问myfile.php时,如何从myfile.php获取$ current_id

1 个答案:

答案 0 :(得分:2)

就在这条线下面:

class Leads extends Common{

添加:

public $current_id = null; // create a public accessible variable

而不是:

$current_id = $this->AddInfoToDB($objInsertArray,"txt",$this->LBCPrimary_leads);

使用:

$this->current_id = $this->AddInfoToDB($objInsertArray,"txt",$this->LBCPrimary_leads);

现在你可以得到它:

$objLeads = new Leads();
echo $objLeads->current_id;