2016-11-03 22 views
0

我有一个phalcon应用程序,它实现了多个子模块。文件夹结构如下所示:用多个视图目录渲染视图

root 
    app 
     controllers 
     models 
     views 
    modules 
     restaurants 
      controllers 
      models 
      views 
     tables 
      controllers 
      models 
      views 
     chairs 
      controllers 
      models 
      views 
    public 

views目录指向modules文件夹。这样,当我必须选择一个视图时,我可以这样做:$this->view->pick('tables/views/index')

现在,我的问题是,当我想渲染一个视图(即获得纯html作为一个字符串),我似乎无法做到这一点。

$this->view->disable(); 

$this->view->pick('restaurants/views/pdf'); 

$html = $this->view->getContent(); 
$html = utf8_encode($html); 

$pdf = new mPDF(); 
$pdf->WriteHTML($html); 
$pdf->SetTitle('This is a test'); 
$pdf->Output('test.pdf', "I"); 

我可以做/解决这个问题吗?

+0

查看https://docs.phalconphp.com/en/latest/reference/views.html#stand-alone-component – Timothy

回答

0

您可以使用模块名称将适当的视图目录直接设置到您的视图服务中。这样您就不必使用pick功能,因为phalcon会自动将它们与您的控制器相关联。

 $module_name = $di->get('router')->getModuleName(); 

     $viewsDir = __DIR__."/modules/".$module_name."/views/"; 

     $view = new View(); 

     $view->setViewsDir($viewsDir);