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


PHP ViewEvent::setModel方法代碼示例

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


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

示例1: testReturnsNullWhenCannotSelectRenderer

 public function testReturnsNullWhenCannotSelectRenderer()
 {
     $model = new ViewModel();
     $request = new HttpRequest();
     $this->event->setModel($model);
     $this->event->setRequest($request);
     $this->assertNull($this->strategy->selectRenderer($this->event));
 }
開發者ID:wizzvet,項目名稱:ZffHtml2pdf,代碼行數:8,代碼來源:Html2PdfStrategyTest.php

示例2: testSelectRendererReturnsJsonRendererWhenSwaggerViewModelIsPresentInEvent

 public function testSelectRendererReturnsJsonRendererWhenSwaggerViewModelIsPresentInEvent()
 {
     $event = new ViewEvent();
     $event->setName(ViewEvent::EVENT_RENDERER);
     $event->setModel(new ViewModel([]));
     $renderer = $this->strategy->selectRenderer($event);
     $this->assertSame($this->renderer, $renderer);
     return $event;
 }
開發者ID:louiselista,項目名稱:BlueSystem,代碼行數:9,代碼來源:SwaggerViewStrategyTest.php

示例3: testSelectRendererWhenTemplateFound

 public function testSelectRendererWhenTemplateFound()
 {
     $model = $this->getMock('Zend\\View\\Model\\ModelInterface');
     $model->expects($this->at(0))->method('getTemplate')->will($this->returnValue('key1'));
     $event = new ViewEvent();
     $event->setModel($model);
     $result = $this->strategy->selectRenderer($event);
     $this->assertSame($this->renderer, $result);
 }
開發者ID:shitikovkirill,項目名稱:zend-shop.com,代碼行數:9,代碼來源:TwigStrategyTest.php

示例4: testSelectRendererWithExtension

 public function testSelectRendererWithExtension()
 {
     $model = $this->getMock('Zend\\View\\Model\\ModelInterface');
     $model->expects($this->at(0))->method('getTemplate')->will($this->returnValue('test.md'));
     $event = new ViewEvent();
     $event->setModel($model);
     $result = $this->strategy->selectRenderer($event);
     $this->assertInstanceOf('Netorare\\View\\Renderer\\MarkdownRenderer', $result);
 }
開發者ID:sasezaki,項目名稱:netorare,代碼行數:9,代碼來源:PathinfoExtensionStrategyTest.php

示例5: testSelectRendererReturnsApiBlueprintRendererWhenApiBlueprintViewModelIsPresentInEvent

 public function testSelectRendererReturnsApiBlueprintRendererWhenApiBlueprintViewModelIsPresentInEvent()
 {
     $event = new ViewEvent();
     $event->setName(ViewEvent::EVENT_RENDERER);
     $event->setModel(new ApiBlueprintModel(array()));
     $event->setRequest(new HttpRequest());
     $renderer = $this->strategy->selectRenderer($event);
     $this->assertSame($this->renderer, $renderer);
     return $event;
 }
開發者ID:BreiteSeite,項目名稱:zf-apigility-documentation-apiblueprint,代碼行數:10,代碼來源:ApiBlueprintViewStrategyTest.php

示例6: render

 /**
  * 
  * @param ModelInterface $model
  * @return string
  */
 public function render(ModelInterface $model)
 {
     $event = new ViewEvent();
     $event->setName(ViewEvent::EVENT_RENDERER);
     $event->setModel($model);
     $renderers = $this->view->getEventManager()->triggerEventUntil(function ($result) {
         return $result instanceof RendererInterface;
     }, $event);
     return $renderers->last()->render($model);
 }
開發者ID:alex-oleshkevich,項目名稱:zf-extras,代碼行數:15,代碼來源:DirectRenderer.php

示例7: testInjectResponseSetsContentTypeHeaderToApiProblemForApiProblemModel

 /**
  *
  */
 public function testInjectResponseSetsContentTypeHeaderToApiProblemForApiProblemModel()
 {
     $problem = new ApiProblem(500, "Error message");
     $model = new ApiProblemModel($problem);
     $this->event->setModel($model);
     $this->event->setRenderer($this->renderer);
     $this->event->setResult('{"foo":"bar"}');
     $this->strategy->injectResponse($this->event);
     $headers = $this->response->getHeaders();
     $this->assertTrue($headers->has('Content-Type'));
     $header = $headers->get('Content-Type');
     $this->assertEquals('application/problem+json', $header->getFieldValue());
 }
開發者ID:zfcampus,項目名稱:zf-hal,代碼行數:16,代碼來源:HalJsonStrategyTest.php

示例8: testProperlyFillViewModelHelperIfRendererIsSelected

 public function testProperlyFillViewModelHelperIfRendererIsSelected()
 {
     $model = new ResourceViewModel();
     $viewEvent = new ViewEvent();
     $viewEvent->setModel($model);
     $viewModelHelper = $this->getMock(ViewModel::class, [], [], '', false);
     $viewModelHelper->expects($this->once())->method('setRoot')->with($model);
     $viewModelHelper->expects($this->once())->method('setCurrent')->with($model);
     $helperManager = $this->getMock(HelperPluginManager::class, [], [], '', false);
     $helperManager->expects($this->once())->method('setRenderer')->with($this->resourceRenderer);
     $helperManager->expects($this->once())->method('get')->with('viewModel')->willReturn($viewModelHelper);
     $this->resourceRenderer->expects($this->once())->method('getHelperPluginManager')->willReturn($helperManager);
     $this->assertSame($this->resourceRenderer, $this->resourceStrategy->selectRenderer($viewEvent));
 }
開發者ID:omusico,項目名稱:zfr-rest,代碼行數:14,代碼來源:ResourceStrategyTest.php

示例9: onRenderer

 /**
  * @param ViewEvent $viewEvent
  *
  * @return PartialRenderer
  */
 public function onRenderer(ViewEvent $viewEvent)
 {
     $model = $viewEvent->getModel();
     $config = $this->getOptions()->getConfig();
     if ($model instanceof ViewModel && in_array($model->getTemplate(), $config)) {
         $success = false;
         $cacheContent = $this->getCacheManager()->getItem($model->getTemplate(), $success);
         if (true === $success) {
             $partialModel = new PartialViewModel();
             $partialModel->setIsCached(true);
             $partialModel->setCacheContent($cacheContent);
             $partialModel->setTemplate($model->getTemplate());
             $viewEvent->setModel($model);
         }
         return $this->getRenderer();
     }
 }
開發者ID:nbochenko,項目名稱:cache,代碼行數:22,代碼來源:PartialStrategy.php

示例10: testResponseHeadersWithFileName

 public function testResponseHeadersWithFileName()
 {
     $model = new PdfModel();
     $model->setTemplate('basic.phtml');
     $model->setOption('filename', 'testPdfFileName');
     $this->event->setModel($model);
     $this->event->setResponse($this->response);
     $this->event->setRenderer($this->renderer);
     $this->event->setResult($this->renderer->render($model));
     $this->strategy->injectResponse($this->event);
     $headers = $this->event->getResponse()->getHeaders();
     $contentDisposition = $headers->get('Content-Disposition');
     $this->assertInstanceOf('Zend\\Http\\Header\\ContentDisposition', $contentDisposition);
     $this->assertEquals($contentDisposition->getFieldValue(), 'attachment; filename=testPdfFileName.pdf');
     ob_end_flush();
     // Clear out any buffers held by renderers.
 }
開發者ID:raykolbe,項目名稱:DOMPDFModule,代碼行數:17,代碼來源:PdfStrategyTest.php

示例11: testSelectRendererAndInjectResponse

 public function testSelectRendererAndInjectResponse()
 {
     $renderer = new BlockRenderer();
     $strategy = new BlockRendererStrategy($renderer);
     $viewEvent = new ViewEvent();
     $viewEvent->setModel(new ViewModel());
     $this->assertNull($strategy->selectRenderer($viewEvent));
     $dummyBlock = new Dummy();
     $viewEvent->setModel($dummyBlock);
     $this->assertSame($renderer, $strategy->selectRenderer($viewEvent));
     $this->assertNull($strategy->injectResponse($viewEvent));
     $response = new Response();
     $viewEvent->setRenderer($renderer);
     $viewEvent->setResult('test');
     $viewEvent->setResponse($response);
     $strategy->injectResponse($viewEvent);
     $this->assertEquals('test', $response->getContent());
 }
開發者ID:adamdyson,項目名稱:ConLayout,代碼行數:18,代碼來源:BlockStrategyTest.php

示例12: testResponseHeadersWithFileName

 public function testResponseHeadersWithFileName()
 {
     $model = $this->serviceManager->get('PdfModel');
     $model->setTemplate('basic.phtml');
     $model->getPdfOptions()->setFilename('testPdfFileName');
     $model->getPdfOptions()->setFooterLines([['text' => 'top line', 'position' => 'center', 'font' => ['family' => 'Helvetica', 'weight' => 'normal', 'size' => 8]], ['text' => 'second line', 'position' => 'left', 'font' => ['family' => 'Helvetica', 'weight' => 'normal', 'size' => 8]], ['text' => 'third line', 'position' => 'right', 'font' => ['family' => 'Helvetica', 'weight' => 'normal', 'size' => 8]]]);
     $model->getPdfOptions()->setHeaderLines([['text' => 'first line', 'position' => 'center', 'font' => ['family' => 'Helvetica', 'weight' => 'normal', 'size' => 8]]]);
     $this->event->setModel($model);
     $this->event->setResponse($this->response);
     $this->event->setRenderer($this->renderer);
     $this->event->setResult($this->renderer->render($model));
     $this->strategy->injectResponse($this->event);
     $headers = $this->event->getResponse()->getHeaders();
     $contentDispositionHeader = $headers->get('Content-Disposition');
     $this->assertInstanceof('Zend\\Http\\Header\\ContentDisposition', $contentDispositionHeader);
     $this->assertEquals($contentDispositionHeader->getFieldValue(), 'attachment; filename=testPdfFileName.pdf');
     ob_end_flush();
 }
開發者ID:uthando-cms,項目名稱:uthando-dompdf,代碼行數:18,代碼來源:PdfStrategyTest.php

示例13: cleanLayout

 /**
  * remove unwanted or layout related data
  *
  * basically you rake through the viewmodel for the data you want to use for your template,
  * this may not be optimal because you have to rely on the correct naming of the viewmodels
  *
  * if you get the data you want, you switch to the specific template by adding the conforming resolver
  *
  * @param \Zend\View\ViewEvent $e
  */
 public function cleanLayout(ViewEvent $e)
 {
     $result = $e->getResult();
     $response = $e->getResponse();
     $model = $e->getModel();
     if ($model->hasChildren()) {
         $children = $model->getChildren();
         $content = null;
         foreach ($children as $child) {
             if ($child->captureTo() == 'content') {
                 $content = $child;
                 $this->attachViewResolver();
             }
         }
         if (!empty($content)) {
             $e->setModel($content);
         }
     } else {
         // attach the own resolver here too ?
         // ...
     }
 }
開發者ID:utrenkner,項目名稱:YAWIK,代碼行數:32,代碼來源:Module.php

示例14: testSelectRendererApplicable

 public function testSelectRendererApplicable()
 {
     $e = new ViewEvent();
     $e->setModel(new YamlModel());
     $this->assertSame($this->renderer, $this->strategy->selectRenderer($e));
 }
開發者ID:acelaya,項目名稱:zf2-acyaml,代碼行數:6,代碼來源:YamlStrategyTest.php

示例15: testAnotherModel

 public function testAnotherModel()
 {
     $viewEvent = new ViewEvent();
     $viewEvent->setModel(new ViewModel());
     $this->strategy->selectRenderer($viewEvent);
 }
開發者ID:shitikovkirill,項目名稱:zend-shop.com,代碼行數:6,代碼來源:ImageStrategyTest.php


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