lopes_andre Posted December 21, 2010 Share Posted December 21, 2010 Hi, I'm giving my first steps with OOP PHP. I need do pass a property in a object call but I can't do it. Here is the code: <?php $testar_classe = new geoIpImportCSV('geolitecity', 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/'); echo $testar_classe->downloadAndSaveFile('./', $testar_classe->obtainDownloadFileName()); echo $testar_classe->uncompressZipFile($testar_classe->toDownloadFileName, './'); //echo $testar_classe->deleteLine(1, 'GeoLiteCity-Location.csv'); //echo $testar_classe->deleteLine(1, 'GeoLiteCity-Blocks.csv'); //echo $testar_classe->insertLinesToDb('GeoLiteCity-Location.csv', 'tabela1'); //echo $testar_classe->insertLinesToDb('GeoLiteCity-Blocks.csv', 'tabela2'); class geoIpImportCSV { // Propriedades Privadas private $input_zip_file; private $url_without_file; private $input_csv_file; private $csvType; private $toSaveDir; // Propriedades Públicas public $toDownloadFileName; function __construct($csvType, $url_without_file) { $this->url_without_file = $url_without_file; $this->csvType = $csvType; } //.. more code here ... /* Este método faz o download e salva o ficheiro em questão no disco. */ public function downloadAndSaveFile($toSaveDir, $toDownloadFilename) { // Vou assignar a $toSaveDir como variavel de classe $this->toSaveDir = $toSaveDir; // Vou saber qual o URL do ficheiro a fazer download $urlFilenameToDownload = $this->url_without_file . $toDownloadFilename; //$urlFilenameToDownload = "http://geolite.maxmind.com/download/geoip/database/GeoIPv6.csv.gz"; // Para efeitos de DEBUG, COMENTAR/APAGAR // Vou fazer o download do ficheiro e gravar p o disco if (isset($urlFilenameToDownload) == true){ $ToDir = $toSaveDir; ## Where the files will be made on your server. $FileContents = implode('', file($urlFilenameToDownload)); $FileNameP = explode('/', $urlFilenameToDownload); $FileName = $FileNameP[count($FileNameP) - 1]; if (($FileContents != '') && (fopen($ToDir . $FileName, 'w') != 0)){ $File = fopen($ToDir . $FileName, 'w'); $Write = fwrite($File, $FileContents); if ($Write != 0){ echo 'The file ' . $ToDir . $FileName . ' was successfully created!'; fclose($File); } else{ echo 'There was an error; the file could not be created.'; } } } } /* Este método descomprime ficheiros zip e coloca-os numa directoria. */ public function uncompressZipFile ($fileNameToUncompress, $extractTo) { // Criar a instancia $zip = new ZipArchive; // Abrir $open_file = $zip->open($fileNameToUncompress); // Extrair para $extract_file_to = $zip->extractTo($extractTo); // Fechar $close_zip = $zip->close(); // Ver se correu tudo bem if(!$close_zip) { die("Error: the uncompress Zip has not have complete correctly."); } else { return "ok"; } } /.. more code here .. } ?> What I'm trying to achieve is to call the property "$toDownloadFileName" in the call to the object "echo $testar_classe->uncompressZipFile($testar_classe->toDownloadFileName, './');" but gives me error. If I call in this way, it works: "echo $testar_classe->uncompressZipFile(/*$testar_classe->toDownloadFileName*/ 'GeoLiteCity_20101201.zip', './');" How can I call the property of the class in the object method? Best Regards, Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 21, 2010 Share Posted December 21, 2010 You don't need to include it in a call to the method. Since it is previously defined you can call it IN the method using $this->toDownloadFileName Example: The Call [ echo $testar_classe->uncompressZipFile('GeoLiteCity_20101201.zip', './'); The method public function uncompressZipFile ($fileNameToUncompress, $extractTo) { // Criar a instancia $zip = new ZipArchive; // Abrir $open_file = $this->toDownloadFileName . $zip->open($fileNameToUncompress); // Extrair para $extract_file_to = $zip->extractTo($extractTo); Quote Link to comment Share on other sites More sharing options...
lopes_andre Posted December 21, 2010 Author Share Posted December 21, 2010 Thanks, it is solved! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.