php Zend-View-Renderer-PhpRenderer类(方法)实例源码

下面列出了php Zend-View-Renderer-PhpRenderer 类(方法)源码代码实例,从而了解它的用法。

作者:vikas1mon    项目:ProductionWs   
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');
 }

作者:zend-module    项目:maintenanc   
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;
 }

作者:patrov    项目:omeka-   
/**
  * {@inheritDoc}
  */
 public function form(PhpRenderer $view, array $options = [])
 {
     $urlInput = new UrlElement('o:media[__index__][o:source]');
     $urlInput->setOptions(['label' => $view->translate('oEmbed URL'), 'info' => $view->translate('URL for the media to embed.')]);
     $urlInput->setAttributes(['id' => 'media-oembed-source-__index__', 'required' => true]);
     return $view->formRow($urlInput);
 }

作者:tc    项目:zf2-imageresize   
protected function setUp()
 {
     $this->view = new PhpRenderer();
     $this->view->getHelperPluginManager()->get('basePath')->setBasePath('/');
     $this->helper = new Resize();
     $this->helper->setView($this->view);
 }

作者:kuisat    项目:ustalarMerkez   
/**
  * @param  ContainerInterface $container
  * @param  string $name
  * @param  null|array $options
  * @return PhpRenderer
  */
 public function __invoke(ContainerInterface $container, $name, array $options = null)
 {
     $renderer = new PhpRenderer();
     $renderer->setHelperPluginManager($container->get('ViewHelperManager'));
     $renderer->setResolver($container->get('ViewResolver'));
     return $renderer;
 }

作者:oq    项目:ci-zend-form-twig-extensio   
/**
  * @param ContainerInterface $container
  *
  * @return PhpRenderer
  */
 public function __invoke(ContainerInterface $container)
 {
     $helper = $container->get(HelperPluginManager::class);
     $renderer = new PhpRenderer();
     $renderer->setHelperPluginManager($helper);
     return $renderer;
 }

作者:adamdyso    项目:ConLayou   
public function testApplyViewHelpers()
 {
     $config = Bootstrap::getServiceManager()->get('Config');
     $helperPluginManager = new HelperPluginManager();
     $listener = new ViewHelperListener($this->layoutUpdater, $helperPluginManager, $config['con-layout']['view_helpers']);
     $mvcEvent = new \Zend\Mvc\MvcEvent();
     $renderer = new PhpRenderer();
     $renderer->setHelperPluginManager($helperPluginManager);
     $basePath = $helperPluginManager->get('basePath');
     $basePath->setBasePath('/assets');
     $basePathAssetPreparer = new BasePath($basePath);
     $listener->addAssetPreparer('headLink', $basePathAssetPreparer);
     /* @var $headLink HeadLink */
     $headLink = $helperPluginManager->get('headLink');
     /* @var $headScript HeadScript */
     $headScript = $helperPluginManager->get('headScript');
     /* @var $doctype \Zend\View\Helper\Doctype */
     $doctype = $helperPluginManager->get('doctype');
     /* @var $headTitle HeadTitle */
     $headTitle = $helperPluginManager->get('headTitle');
     /* @var $headMeta HeadMeta */
     $headMeta = $helperPluginManager->get('headMeta');
     $headMeta->setView($renderer);
     $listener->applyViewHelpers($mvcEvent);
     $expected = '<link href="/assets/css/test.css" media="screen" rel="stylesheet" type="text/css">' . PHP_EOL . '<link href="/assets/css/main.css" media="screen" rel="stylesheet" type="text/css">';
     $this->assertEquals($expected, $headLink->toString());
     $expected = '<script type="text/javascript" src="/js/jquery.min.js"></script>' . PHP_EOL . '<script type="text/javascript" src="/js/jquery-ui.min.js"></script>' . PHP_EOL . '<!--[if lt IE 9]><script type="text/javascript" src="/js/modernizr.js"></script><![endif]-->' . PHP_EOL . '<script type="text/javascript" src="/js/functions.js"></script>';
     $this->assertEquals($expected, $headScript->toString());
     $this->assertEquals('<!DOCTYPE html>', (string) $doctype);
     $headTitle->setSeparator(' | ');
     $expected = '<title>First | My Title | Another Title</title>';
     $this->assertEquals($expected, $headTitle->toString());
     $expected = '<meta charset="utf8">' . PHP_EOL . '<meta name="description" content="My description">' . PHP_EOL . '<meta name="keywords" content="keyword1, keyword2, keyword3">';
     $this->assertEquals($expected, $headMeta->toString());
 }

作者:till    项目:vufin   
/**
  * Support function to display spelling suggestions.
  *
  * @param string                          $msg     HTML to display at the top of
  * the spelling section.
  * @param \VuFind\Search\Base\Results     $results Results object
  * @param \Zend\View\Renderer\PhpRenderer $view    View renderer object
  *
  * @return string
  */
 public function renderSpellingSuggestions($msg, $results, $view)
 {
     $spellingSuggestions = $results->getSpellingSuggestions();
     if (empty($spellingSuggestions)) {
         return '';
     }
     $html = '<div class="' . $this->getContainerClass() . '">';
     $html .= $msg;
     foreach ($spellingSuggestions as $term => $details) {
         $html .= '<br/>' . $view->escapeHtml($term) . ' &raquo; ';
         $i = 0;
         foreach ($details['suggestions'] as $word => $data) {
             if ($i++ > 0) {
                 $html .= ', ';
             }
             $html .= '<a href="' . $results->getUrlQuery()->replaceTerm($term, $data['new_term']) . '">' . $view->escapeHtml($word) . '</a>';
             if (isset($data['expand_term']) && !empty($data['expand_term'])) {
                 $url = $results->getUrlQuery()->replaceTerm($term, $data['expand_term']);
                 $html .= $this->renderExpandLink($url, $view);
             }
         }
     }
     $html .= '</div>';
     return $html;
 }

作者:razvansividr    项目:pnlzf2-   
/**
  * Prepares the environment before running a test
  *
  */
 protected function setUp()
 {
     $cwd = __DIR__;
     // read navigation config
     $this->_files = $cwd . '/_files';
     $config = ConfigFactory::fromFile($this->_files . '/navigation.xml', true);
     // setup containers from config
     $this->_nav1 = new Navigation($config->get('nav_test1'));
     $this->_nav2 = new Navigation($config->get('nav_test2'));
     // setup view
     $view = new PhpRenderer();
     $view->resolver()->addPath($cwd . '/_files/mvc/views');
     // create helper
     $this->_helper = new $this->_helperName();
     $this->_helper->setView($view);
     // set nav1 in helper as default
     $this->_helper->setContainer($this->_nav1);
     // setup service manager
     $smConfig = array('modules' => array(), 'module_listener_options' => array('config_cache_enabled' => false, 'cache_dir' => 'data/cache', 'module_paths' => array(), 'extra_config' => array('service_manager' => array('factories' => array('Config' => function () use($config) {
         return array('navigation' => array('default' => $config->get('nav_test1')));
     })))));
     $sm = $this->serviceManager = new ServiceManager(new ServiceManagerConfig());
     $sm->setService('ApplicationConfig', $smConfig);
     $sm->get('ModuleManager')->loadModules();
     $sm->get('Application')->bootstrap();
     $sm->setFactory('Navigation', 'Zend\\Navigation\\Service\\DefaultNavigationFactory');
     $sm->setService('nav1', $this->_nav1);
     $sm->setService('nav2', $this->_nav2);
     $app = $this->serviceManager->get('Application');
     $app->getMvcEvent()->setRouteMatch(new RouteMatch(array('controller' => 'post', 'action' => 'view', 'id' => '1337')));
 }

作者:netsensi    项目:zf2-foundatio   
/**
  * @outputBuffering disabled
  */
 public function testCanRenderFieldsets()
 {
     $this->expectOutputRegex('/<form(.*)<fieldset(.*)<\\/fieldset>(.*)<fieldset(.*)<\\/fieldset>(.*)<\\/form>/');
     $form = new NetsensiaForm();
     $form->addHidden('test1', 'testvalue');
     $hidden = new Element\Hidden('asdasd');
     $hidden->setValue('123');
     $form->add($hidden);
     $element1 = new Text('testelement1');
     $element1->setLabel('Test Element');
     $element1->setAttribute('icon', 'pencil');
     $element2 = new Text('testelement2');
     $element2->setLabel('Test Element 2');
     $element2->setAttribute('icon', 'pencil');
     $fieldset1 = new Fieldset('testfieldset1');
     $fieldset1->add($element1);
     $fieldset2 = new Fieldset('testfieldset2');
     $fieldset2->add($element2);
     $form->add($fieldset1);
     $form->add($fieldset2);
     $helpers = new HelperPluginManager();
     $helpers->setService('formElement', new FormElement());
     $view = new PhpRenderer();
     $view->setHelperPluginManager($helpers);
     $viewHelper = new BootstrapForm();
     $viewHelper->setView($view);
     $viewHelper($form, 'testform', '/');
 }

作者:hummer2    项目:conlayou   
public function setUp()
 {
     $this->wrapperHelper = new Wrapper();
     $view = new PhpRenderer();
     $view->setHelperPluginManager(new HelperPluginManager());
     $this->wrapperHelper->setView($view);
 }

作者:patrov    项目:omeka-   
public function render(PhpRenderer $view, SitePageBlockRepresentation $block)
 {
     $attachments = $block->attachments();
     if (!$attachments) {
         return '';
     }
     $html = '';
     foreach ($attachments as $attachment) {
         $html .= '<div>';
         $item = $attachment->item();
         if ($item) {
             $html .= '<h2>' . $item->link($item->displayTitle()) . '</h2>';
             $media = $attachment->media();
             if (!$media) {
                 $media = $item->primaryMedia();
             }
             if ($media) {
                 $thumbnailType = $this->getData($block->data(), 'thumbnail_type', 'square');
                 $html .= '<h3>' . $media->link($media->displayTitle()) . '</h3>';
                 $html .= '<img src="' . $view->escapeHtml($media->thumbnailUrl($thumbnailType)) . '">';
             }
         }
         $caption = $attachment->caption();
         if ($caption) {
             $html .= '<p>' . $caption . '</p>';
         }
         $html .= '</div>';
     }
     return $html;
 }

作者:quangdungnin    项目:zendvntea   
public function setUp()
 {
     $this->transport = new MockTransport();
     $config = (include __DIR__ . '/../../config/module.config.php');
     $renderer = new PhpRenderer();
     $renderer->setResolver(new TemplatePathStack($config['view_manager']['template_path_stack']));
     $this->mailService = new MailService(new Message(), $this->transport, $renderer);
 }

作者:patrov    项目:omeka-   
public function render(PhpRenderer $view, SitePageBlockRepresentation $block)
 {
     $html = '';
     $html .= '<div class="navigation-block">';
     $html .= $view->navigation('Zend\\Navigation\\Site')->menu()->renderSubMenu();
     $html .= '</div>';
     return $html;
 }

作者:ripaclu    项目:zf2-hanger-snippe   
/**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->helper = new SnippetHelper();
     $view = new PhpRenderer();
     $view->resolver()->addPath(__DIR__ . '/../../../view');
     $view->resolver()->addPath(__DIR__ . '/_files/modules');
     $this->helper->setView($view);
 }

作者:acelay    项目:zf2-acqrcod   
public function setUp()
 {
     $config = (include __DIR__ . '/../../../config/module.config.php');
     $renderer = new PhpRenderer();
     $renderer->setResolver(new TemplateMapResolver($config['view_manager']['template_map']));
     $router = TreeRouteStack::factory($config['router']);
     $this->helper = new QrCodeHelper($renderer, $router, new QrCodeServiceMock('foobar'));
 }

作者:razvansividr    项目:pnlzf2-   
public function testRaisesExceptionIfViewModelHelperHasNoRoot()
 {
     $renderer = new PhpRenderer();
     $viewModelHelper = $renderer->plugin('view_model');
     $helper = $renderer->plugin('layout');
     $this->setExpectedException('Zend\\View\\Exception\\RuntimeException', 'view model');
     $helper->setTemplate('foo/bar');
 }

作者:patrov    项目:omeka-   
/**
  * {@inheritDoc}
  */
 public function form(PhpRenderer $view, array $options = [])
 {
     $fileInput = new File('file[__index__]');
     $fileInput->setOptions(['label' => $view->translate('Upload File')]);
     $fileInput->setAttributes(['id' => 'media-file-input-__index__']);
     $field = $view->formRow($fileInput);
     return $field . '<input type="hidden" name="o:media[__index__][file_index]" value="__index__">';
 }

作者:SalesAndOrder    项目:zf2-mai   
/**
  * @return PhpRenderer
  */
 public function getTestRenderer()
 {
     $resolver = new TemplatePathStack();
     $resolver->addPath(__DIR__ . '/../views');
     $renderer = new PhpRenderer();
     $renderer->setResolver($resolver);
     return $renderer;
 }

作者:enlitepr    项目:enlite-mai   
/**
  * @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;
 }


问题


面经


文章

微信
公众号

扫码关注公众号