本文整理汇总了PHP中Zend\View\Renderer\PhpRenderer::render方法的典型用法代码示例。如果您正苦于以下问题:PHP PhpRenderer::render方法的具体用法?PHP PhpRenderer::render怎么用?PHP PhpRenderer::render使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\Renderer\PhpRenderer
的用法示例。
在下文中一共展示了PhpRenderer::render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: PdfAction
public function PdfAction()
{
$pdf = new TCPDF('L');
$pdf->SetPrintHeader(true);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
require_once dirname(__FILE__) . '/lang/eng.php';
$pdf->setLanguageArray($l);
}
// set font
$pdf->SetFont('helvetica', '', 8);
// add a page
$pdf->AddPage();
//get report data into $data variable
$project = $this->getServiceLocator()->get('ProjectTable');
$data = $project->getWsr();
$view = new PhpRenderer();
$resolver = new TemplateMapResolver();
//set the path of the pdf.phtml file
$resolver->setMap(array('PDFTemplate' => '/var/www/html/WSRAutomation/module/Application/view/application/index/pdf.phtml'));
$view->setResolver($resolver);
$viewModel = new ViewModel();
$viewModel->setTemplate('PDFTemplate')->setVariables(array('projects' => $data, 'view' => 'pdf'));
$html = $view->render($viewModel);
$pdf->writeHTML($html, true, 0, true, 0);
$pdf->Output('WsrReport.pdf', 'I');
}
示例2: onRoute
public function onRoute(MvcEvent $e)
{
$request = $e->getRequest();
if (!$request instanceof HttpRequest) {
return;
}
$application = $e->getApplication();
$serviceLocator = $application->getServiceManager();
// Load the configuration for maintenance mode
if ($serviceLocator->has('MaintenanceConfig')) {
$config = $serviceLocator->get('MaintenanceConfig');
} else {
$config = new Config();
}
if (!$config->isEnabled()) {
// Maintenance mode is disabled.
return;
}
// Check the white list
if ($request instanceof PhpRequest) {
$address = $request->getServer('REMOTE_ADDR', null);
} else {
$address = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
}
if (!empty($address)) {
if (in_array($address, $config->getWhitelist())) {
return;
}
}
// Render the maintenance layout
$renderer = new PhpRenderer();
if ($serviceLocator->has('ViewHelperManager')) {
$renderer->setHelperPluginManager($serviceLocator->get('ViewHelperManager'));
}
$resolver = new TemplateMapResolver();
$resolver->add('maintenance', $config->getTemplate());
$renderer->setResolver($resolver);
$content = $renderer->render('maintenance');
// Set the response
$response = $e->getResponse();
if (!$response instanceof HttpResponse) {
$response = new HttpResponse();
}
$statusCode = $config->getStatusCode();
$response->setStatusCode($statusCode);
if ($statusCode === 503 && !$response->getHeaders()->has('Retry-After')) {
$retryDate = $config->getRetryAfter();
if ($retryDate instanceof DateTime) {
$retryAfter = new RetryAfter();
$retryAfter->setDate($retryDate);
$response->getHeaders()->addHeader($retryAfter);
}
}
$response->setContent($content);
$e->setResponse($response);
// Return the response
return $response;
}
示例3: testFromRenderWithCheckbox
public function testFromRenderWithCheckbox()
{
$formConfig = ['template' => 't4web-form-renderer/element/form', 'children' => ['terms' => ['template' => 't4web-form-renderer/element/checkbox', 'variables' => ['label' => 'Terms']]], 'variables' => ['action' => '/admin/news/create', 'cancelLink' => '/admin/list']];
$factory = new Factory();
$form = $factory->create($formConfig);
$form->setData(['terms' => 1]);
$form->setMessages(['terms' => ["You must read and check"]]);
$rawHtml = $this->renderer->render($form);
$this->assertEquals(preg_replace('/\\s+/', ' ', '<form method="post" action="/admin/news/create">
<div class="box-body">
<div class="form-group has-error">
<div class="checkbox">
<label>
<input type="checkbox" name="terms" value="1"> Terms
</label>
</div>
<p class="help-block">You must read and check</p>
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-success" id="submit-btn">Submit</button>
<a class="btn btn-default" href="/admin/list">Cancel</a>
</div>
</form>'), preg_replace('/\\s+/', ' ', $rawHtml));
}
示例4: render
/**
* @param Message $message
* @return Message
*/
public function render(Message $message)
{
$viewModel = new ViewModel($this->variables);
$viewModel->setTemplate($this->template);
$helperPluginManager = $this->renderer->getHelperPluginManager();
/** @var HeadTitle $helper */
$helper = $helperPluginManager->get('HeadTitle');
// replace headTitle
$headTitle = new HeadTitle();
$headTitle->setAutoEscape(false);
$helperPluginManager->setAllowOverride(true);
$helperPluginManager->setService('HeadTitle', $headTitle);
if (!$message->getBody()) {
$message->setBody(new MimeMessage());
}
$text = new Part($this->renderer->render($viewModel));
$text->charset = 'UTF-8';
$text->boundary = $message->getBody()->getMime()->boundary();
$text->encoding = Mime::ENCODING_BASE64;
$text->type = Mime::TYPE_HTML;
$message->getBody()->addPart($text);
$message->setSubject($headTitle->renderTitle());
// hack for ZF
$message->setBody($message->getBody());
// restore original helper
$helperPluginManager->setService('HeadTitle', $helper);
return $message;
}
示例5: render
/**
* Render template
*
* @param string $name Name
* @param array $data Data
*
* @return string
*/
public function render($name, array $data = array())
{
$viewModel = new ViewModel();
$viewModel->setTemplate($name);
$viewModel->setVariables($data);
return $this->renderer->render($viewModel);
}
示例6: testFromRenderWithPassword
public function testFromRenderWithPassword()
{
$formConfig = ['template' => 't4web-form-renderer/element/form', 'children' => ['status' => ['template' => 't4web-form-renderer/element/select', 'variables' => ['labels' => [1 => 'Active', 2 => 'In active', 3 => 'Deleted']]]], 'variables' => ['action' => '/admin/news/create', 'cancelLink' => '/admin/list']];
$factory = new Factory();
$form = $factory->create($formConfig);
$form->setData(['status' => 3]);
$form->setMessages(['status' => ["This field is required"]]);
$rawHtml = $this->renderer->render($form);
$this->assertEquals(preg_replace('/\\s+/', ' ', '<form method="post" action="/admin/news/create">
<div class="box-body">
<div class="form-group has-error">
<label>Select</label>
<select name="status" class="form-control">
<option value="1" >Active</option>
<option value="2" >In active</option>
<option value="3" selected>Deleted</option>
</select>
<p class="help-block">This field is required</p>
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-success" id="submit-btn">Submit</button>
<a class="btn btn-default" href="/admin/list">Cancel</a>
</div>
</form>'), preg_replace('/\\s+/', ' ', $rawHtml));
}
示例7: render
public function render($variables, $template)
{
$this->phpRenderer->setVars($variables);
$result = $this->phpRenderer->render($template);
$this->phpRenderer->setVars(array());
return $result;
}
示例8: showAction
public function showAction()
{
$this->composerInfo->parse();
$loadedModules = $this->moduleManager->getLoadedModules();
$packages = $this->composerInfo->getPackages();
$this->viewModel->setPackages($packages);
$this->viewModel->setLoadedModules($loadedModules);
$this->viewModel->setTemplate('list-show');
return $this->renderer->render($this->viewModel);
}
示例9: renderError
public function renderError(MvcEvent $e)
{
$error = $e->getError();
$app = $e->getTarget();
$response = $e->getResponse();
if (!$response) {
$response = new Response();
$e->setResponse($response);
}
if ($response->getStatusCode() == 404) {
$error = $response->getStatusCode();
}
if (!empty($error)) {
switch ($error) {
case Application::ERROR_CONTROLLER_NOT_FOUND:
case Application::ERROR_CONTROLLER_INVALID:
$vars = array('message' => 'Page not found.');
$response->setStatusCode(404);
break;
case Application::ERROR_EXCEPTION:
default:
$exception = $e->getParam('exception');
$vars = array('message' => 'An error occurred during execution, please try again later.', 'exception' => $e->getParam('exception'), 'display_exceptions' => $this->displayExceptions());
$response->setStatusCode(500);
break;
}
$content = $this->view->render('error/index.phtml', $vars);
$e->setResult($content);
return $this->renderLayout($e);
}
return '';
}
示例10: buildMessage
/**
* Build Message
*
* @return MailMessage
*/
public function buildMessage()
{
// prepare html body
$htmlBody = $this->renderer->render($this->viewModel);
// prepare text body
$textBody = $this->buildTextBody($htmlBody);
// prepare subject
$subject = $this->buildSubject($htmlBody);
// prepare html part
$htmlPart = new MimePart($this->buildHtmlHeader() . $htmlBody . $this->buildHtmlFooter());
$htmlPart->type = 'text/html';
// prepare text part
$textPart = new MimePart($textBody);
$textPart->type = 'text/plain';
// prepare mime message
$mailBody = new MimeMessage();
$mailBody->setParts(array($textPart, $htmlPart));
// prepare message
$this->message = new MailMessage();
$this->message->setEncoding($this->encoding);
$this->message->setFrom($this->senderMail, $this->senderName);
$this->message->setSubject($subject);
$this->message->setBody($mailBody);
// return mailer
return $this;
}
示例11: testFromRenderWithHidden
public function testFromRenderWithHidden()
{
$formConfig = ['template' => 't4web-form-renderer/element/form', 'children' => ['id' => ['template' => 't4web-form-renderer/element/hidden']], 'variables' => ['action' => '/admin/news/create', 'cancelLink' => '/admin/list']];
$factory = new Factory();
$form = $factory->create($formConfig);
$form->setData(['id' => 123]);
$rawHtml = $this->renderer->render($form);
$this->assertEquals(preg_replace('/\\s+/', ' ', '<form method="post" action="/admin/news/create">
<div class="box-body">
<input type="hidden" name="id" class="form-control" value="123">
</div>
<div class="box-footer">
<button type="submit" class="btn btn-success" id="submit-btn">Submit</button>
<a class="btn btn-default" href="/admin/list">Cancel</a>
</div>
</form>'), preg_replace('/\\s+/', ' ', $rawHtml));
}
示例12: autocompleteAction
public function autocompleteAction(Request $request, Response $response = null)
{
$serviceManager = $this->getServiceLocator();
$console = $serviceManager->get('console');
$resolver = $serviceManager->get('ViewResolver');
$render = new PhpRenderer();
$render->setResolver($resolver);
$console->write($render->render('client/manual/autocomplete'));
}
示例13: renderTemplatePath
protected function renderTemplatePath($strPath, $arrVariables)
{
$view = new PhpRenderer();
$resolver = new TemplateMapResolver();
$resolver->setMap(array('mailTemplate' => __DIR__ . '/../../../' . $strPath));
$view->setResolver($resolver);
$viewModel = new ViewModel();
$viewModel->setTemplate('mailTemplate')->setVariables($arrVariables);
return $view->render($viewModel);
}
示例14: render
public function render()
{
$renderer = new PhpRenderer();
$resolver = new Resolver\AggregateResolver();
$renderer->setResolver($resolver);
$map = new Resolver\TemplateMapResolver(array(static::getTemplate() => __DIR__ . '/view/' . static::getTemplate() . '.phtml'));
$resolver->attach($map);
// this will be consulted first
return $renderer->render($this);
}
示例15: getContent
public function getContent()
{
$info = new \SplFileInfo($this->file);
$renderer = new PhpRenderer();
$stack = new TemplatePathStack();
$stack->addPath($info->getPath());
$stack->setDefaultSuffix(pathinfo($this->file, PATHINFO_EXTENSION));
$renderer->setResolver($stack);
return $renderer->render($info->getBasename());
}