PHP code example of m-adamski / symfony-helpers-bundle

1. Go to this page and download the library: Download m-adamski/symfony-helpers-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

m-adamski / symfony-helpers-bundle example snippets

(php)
$this->breadcrumbsHelper->addRouteItem("Management", "administrator.index", [], "navigation");
$this->breadcrumbsHelper->addRouteItem("Data management", "administrator.data", ["id" => $id], "navigation");
(php)
$messageSubject = "This is example message";
$messageTemplate = "mail/Notification/notification.html.twig";

$messageData = [
    "template_parameter" => "Hello World!"
];

$messageAttachments = [
    $this->directoryHelper->generatePath([
        $this->directoryHelper->getPublicDirectory(), "download", "information.pdf"
    ], true)
];

// Send message
$this->mailerHelper->sendMessage(["[email protected]"], $messageSubject, $messageTemplate, $messageData, $messageAttachments);
(php)
$this->notificationHelper->addNotification(
    NotificationHelper::ERROR_TYPE,
    $this->translator->trans("An error occurred while trying to create a entry", [], "blog")
);
(php)
public function index(Request $request, int $page) {
    return $this->render("modules/News/index.html.twig", [
        "page" => $page,
        "news" => $this->paginationHelper->responseData($request, $this->newsRepository, $page)
    ]);
}
(php)
public function getPaginated(int $page = 1, int $limit = 20) {
    $queryBuilder = $this->getEntityManager()->getRepository("App:News")
        ->createQueryBuilder("news");

    $queryBuilder->where($queryBuilder->expr()->eq("news.public", true))
        ->orderBy("news.createdAt", "DESC");

    return $this->paginate($queryBuilder->getQuery(), $page, $limit);
}
(php)
$pdfName = "Sample PDF document";

// Generate PDF template
$documentContent = $this->renderView("pdf/document-content.html.twig", [
    "data" => $data
]);

// Generate PDF document
$pdfDocument = $this->pdfHelper->initDocument();
$pdfDocument->setTitle($pdfName);
$pdfDocument->setAuthor("Author");
$pdfDocument->setCreator("Creatot");
$pdfDocument->setFooter($pdfName);
$pdfDocument->writeHTML($documentContent);

// Generate response
$response = new Response(
    $pdfDocument->output($pdfName)
);

$response->headers->set("Content-Type", "application/pdf");
$response->headers->set("Content-Disposition", "attachment; filename=\"" . $pdfName . ".pdf\"");

return $response;