I thought I can call a method directly with classname::method but it didn’t work. How is this possible? I traced the function call with xdebug but it gives me an error. Would it be a problem when the method needs some class variable?
This works:
$a = new export_csv();
$a->dl_csv();
This don’t: export_csv::dl_csv();
I’ve added public static to my method to no avail. I don’t get anything in the log files and xdebug stop working without an error message? Is this normal? My class includes some class and connect to my database and pull and echo some rows?
require_once(PATH_t3lib.'class.t3lib_db.php');
require_once(PATH_t3lib.'class.t3lib_div.php');
require_once(PATH_t3lib.'utility/class.t3lib_utility_math.php');
class export_csv
{
var $filename = 'meinname.csv';
public static function dl_csv()
{
// bitte nicht ändern muß zur laufzeit geladen werden
include(PATH_typo3conf.'localconf.php');
$GLOBALS['TYPO3_DB'] = t3lib_div::makeInstance('t3lib_DB');
$GLOBALS['TYPO3_DB']->connectDB($typo_db_host, $typo_db_username,
$typo_db_password, $typo_db);
session_start();
$targetCat = mysql_real_escape_string($_SESSION['targetCat']);
// calculate the number of rows for the query. We need this for paging the
result
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 'V.title VT, V.uid VU,
S.title ST, S.uid SU, S1.uid S1U, S1.title S1T',
'tx_category V
INNER JOIN tx_category S ON
V.parent_category=S.uid
INNER JOIN tx_category S1 ON
S.parent_category=S1.uid',
'V.uid='.$targetCat.' OR S.uid='.
$targetCat.' OR S1.uid='.
$targetCat.
' AND V.deleted=0 AND V.hidden=0',
'',
'',
''
);
$arrcount=0;
while ( $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res) )
{
$categories[] = mysql_real_escape_string($row["VU"]);
++$arrcount;
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type:text/comma-separated-values");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=$this->filename");
if ( $arrcount )
{
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*',
'tx_download',
'category IN('.implode(",",
$categories).")",
'',
"",
""
);
while ($row = mysql_fetch_assoc($res) )
{
$s = array ();
$s[] = $row['1'];
$s[] = $row['2'];
$s[] = $row['3'];
$s[] = $row['4'];
$s[] = $row['5'];
echo '"'. substr ( implode ( '","', $s ),0,strlen ( implode ( '","', $s) ) - 2 ) . "\r\n";
}
}
}
}
Methods defined as
static, which therefore cannot make use of instance properties/methods (via$this) can be called statically via:Review the PHP documentation on
staticmethods and propertiesUpdate after seeing mode code:
Your
dl_csv()function accesses$this->filenamein the output headers, which is invalid inside a static call.Instead, you would need to define the
$filenameas a static property as well and call viaself:::