Hi,
I made module PageAddons (Object::add_extension('Page_Controller','PageAddons');)
class PageAddons extends Extension {
..............................
}
When I add methods ToPrint() and ToPDf() to Page_Controller, it is visible and works.
class Page_Controller extends ContentController {
............................
public function ToPrint() {
$absoluteBase = Director::absoluteBaseURL();
$current_theme = SSViewer::current_theme();
Requirements::insertHeadTags('<link rel="stylesheet" type="text/css" href="' . $absoluteBase . 'themes/' . $current_theme . '/css/print.css" media="all" />');
$page_url = Controller::curr()->Link();
$page_url = str_replace("/","", substr( $page_url, 1) );
$filename = trim( $page_url . '.html' );
$filename_path = ASSETS_PATH . '/.private/'. $filename;
$htmlFile = Director::absoluteBaseURL() . ASSETS_DIR . '/.private/'. $filename;
$Rendered = $this;
$Rendered = $this->customise( $Rendered )->renderWith( array( 'Page_print','Page' ) );
if ( file_exists( $filename_path ) ) unlink ( $filename_path );
$fh = fopen( $filename_path, "wb" ) or user_error( "Couldn't open $filename for writing", E_USER_ERROR );
fwrite( $fh, $Rendered ) or user_error( "Couldn't write content to $filename", E_USER_ERROR );
fclose( $fh );
Director::redirect( $htmlFile );
}
public function ToPdf() {
$absoluteBase = Director::absoluteBaseURL();
$current_theme = SSViewer::current_theme();
Requirements::insertHeadTags('<link rel="stylesheet" type="text/css" href="' . $absoluteBase . 'themes/' . $current_theme . '/css/print.css" media="all" />');
$page_url = Controller::curr()->Link();
$page_url = str_replace("/",'', $page_url );
$filename = $page_url; // no extension ".pdf"
$Rendered = $this;
$Rendered = $this->customise( $Rendered )->renderWith( array( 'Page_print','Page' ) );
$pdf = new PageAddonsPDF();
$pdf->setData( $Rendered );
$pdf->setName( $filename );
// param 1 => show page from memory
// param 2 => save to file before show
$pdf->getPDF();
}
.................................
}
But when I put thoses methods to PageAddons, it is not visible and not callable.
class PageAddons extends Extension {
..............................
public function ToPrint() {
$page_url = Controller::curr()->Link();
$page_url = str_replace("/","", substr( $page_url, 1) );
$filename = trim( $page_url . '.html' );
$filename_path = ASSETS_PATH . '/.private/'. $filename;
$htmlFile = Director::absoluteBaseURL() . ASSETS_DIR . '/.private/'. $filename;
$Rendered = $this;
$Rendered = $this->customise( $Rendered )->renderWith( array( 'Page_print' ) );
if ( file_exists( $filename_path ) ) unlink ( $filename_path );
$fh = fopen( $filename_path, "wb" ) or user_error( "Couldn't open $filename for writing", E_USER_ERROR );
fwrite( $fh, $Rendered ) or user_error( "Couldn't write content to $filename", E_USER_ERROR );
fclose( $fh );
Director::redirect( $htmlFile );
}
public function ToPdf() {
$page_url = Controller::curr()->Link();
$page_url = str_replace("/",'', $page_url );
$filename = $page_url; // no extension ".pdf"
$Rendered = $this;
$Rendered = $this->customise( $Rendered )->renderWith( array( 'Page_print' ) );
$pdf = new PageAddonsPDF();
$pdf->setData( $Rendered );
$pdf->setName( $filename );
// param 1 => show page from memory
// param 2 => save to file before show
$pdf->getPDF();
}
..............................
}
Why? Ho can I call those methods directly from PageAddons module?
Can someone help me?