當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Application::getTemplateRepository方法代碼示例

本文整理匯總了PHP中Silex\Application::getTemplateRepository方法的典型用法代碼示例。如果您正苦於以下問題:PHP Application::getTemplateRepository方法的具體用法?PHP Application::getTemplateRepository怎麽用?PHP Application::getTemplateRepository使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Silex\Application的用法示例。


在下文中一共展示了Application::getTemplateRepository方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: rootAction

 public function rootAction(Application $app, Request $request)
 {
     $data = $this->prepareInput();
     if ($data === null) {
         return new JsonResponse(['error' => 'no json data found'], 400);
     }
     $templateName = isset($data['template']) ? $data['template'] : null;
     $templateData = isset($data['data']) ? $data['data'] : null;
     if (!$templateName || !$templateData) {
         return new JsonResponse(['error' => 'template and data must be set'], 400);
     }
     $repo = $app->getTemplateRepository();
     $template = $repo->getByName($templateName);
     if (!$template) {
         return new JsonResponse(['error' => "template {$templateName} not found"], 404);
     }
     $twig = new \Twig_Environment(new \Twig_Loader_String());
     $html = $twig->render($template->getTemplate(), $templateData);
     $file = new File();
     $file->setId(Uuid::uuid4()->toString());
     $file->setCreatedAt(date('Y-m-d H:i:s'));
     $file->setPath($this->getFilePath($file));
     $snappy = new Pdf();
     if (substr(php_uname(), 0, 7) == "Windows") {
         $snappy->setBinary('vendor\\bin\\wkhtmltopdf.exe.bat');
     } else {
         $snappy->setBinary('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64');
     }
     $snappy->generateFromHtml($html, $file->getPath());
     $repo = $app->getFileRepository();
     $repo->add($file);
     return new JsonResponse(['id' => $file->getId()], 201);
 }
開發者ID:v03adk,項目名稱:pdf-generation-server,代碼行數:33,代碼來源:ApiController.php

示例2: getTemplateEditForm

 private function getTemplateEditForm(Application $app, Request $request, $templateId)
 {
     $error = $request->query->get('error');
     $repo = $app->getTemplateRepository();
     $add = false;
     $template = $repo->getById($templateId);
     if ($template === null) {
         $defaults = null;
         $add = true;
     } else {
         $defaults = ['name' => $template->getName(), 'template' => $template->getTemplate(), 'description' => $template->getDescription()];
     }
     $form = $app['form.factory']->createBuilder('form', $defaults)->add('name', 'text')->add('template', 'textarea')->add('description', 'textarea', array('required' => false))->getForm();
     // handle form submission
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         if ($add) {
             $template = new Template();
         }
         $template->setTemplate($data['template'])->setName($data['name'])->setDescription($data['description']);
         if ($add) {
             if (!$repo->add($template)) {
                 return $app->redirect($app['url_generator']->generate('templates_add', array('error' => 'Failed adding template')));
             }
         } else {
             $repo->update($template);
         }
         return $app->redirect($app['url_generator']->generate('templates_index'));
     }
     return new Response($app['twig']->render('templates/edit.html.twig', ['form' => $form->createView(), 'template' => $template, 'error' => $error]));
 }
開發者ID:v03adk,項目名稱:pdf-generation-server,代碼行數:32,代碼來源:TemplateController.php


注:本文中的Silex\Application::getTemplateRepository方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。