Category «Silverstripe»

Create/generate PDF file in Silverstripe via Dompdf

install dompdf first: composer require dompdf/dompdf in Silverstripe controller: use Dompdf\Dompdf; use SilverStripe\Control\Email\Email; $pdfHtml = $memberapplication->renderWith(‘PDF/NewMemberPdf’); exit($pdfHtml); // uncomment for pdf debug $dompdf = newDompdf(); $dompdf->loadHtml($pdfHtml); $dompdf->setPaper(‘A4’, ‘portrait’); $dompdf->render(); //$dompdf->stream(); $pdfData = $dompdf->output(); $pdfFilename = ‘pdf/NewMemberPdf-‘.$memberapplication->ID.’.pdf’; file_put_contents($pdfFilename,$pdfData); // will save to public/pdf folder PDF/NewMemberPdf.ss in the SilverStripe templates folder usingĀ $memberapplication object’s variables send an email …

Silverstripe RESTful service API cross origin Access-Control-Allow-Origin issue

Add below to index.php for test if ( strpos($_SERVER[‘REQUEST_URI’], ‘/api/v1/’ ) !== false ){ // only allow GET, OPTIONS for all api header(‘Access-Control-Allow-Origin: *’); header(‘Access-Control-Allow-Methods: GET, OPTIONS’); header(‘Access-Control-Allow-Credentials: true’); header(‘Access-Control-Allow-Headers: Authorization, Content-Type, x-xsrf-token, x_csrftoken, x-csrf-token, x-requested-with, Cache-Control, X-Requested-With, Origin, Accept’); header(‘Content-Type: application/json’); if ($_SERVER[‘REQUEST_METHOD’] === ‘OPTIONS’) { echojson_encode($_SERVER[‘REQUEST_URI’]); exit(); } } // Build request and …