Php 有没有办法从CodeIgniter中的控制器加载内联视图片段?

Php 有没有办法从CodeIgniter中的控制器加载内联视图片段?,php,codeigniter,Php,Codeigniter,假设我有一个控制器函数,其中有以下几行: $this->load->view('stdHeader_view'); echo "<div class='main'>"; $this->loadView('foo_view'); echo '</div>'; $this->load->view('stdFooter_view'); 那么,有没有一种方法可以实现我想要的,本质上是在控制器中内联“回显”HTML片段,并使它们相对于加载在它们上面和

假设我有一个控制器函数,其中有以下几行:

$this->load->view('stdHeader_view');
echo "<div class='main'>";
$this->loadView('foo_view');
echo '</div>';
$this->load->view('stdFooter_view');

那么,有没有一种方法可以实现我想要的,本质上是在控制器中内联“回显”HTML片段,并使它们相对于加载在它们上面和下面的视图显示在相同的位置?显然,我可以通过为
创建整个视图文件来实现这一点,但这似乎有点愚蠢。

为什么不这样做? 您应该将变量数据加载到视图中,并从数据中操作视图

如果确实必须这样做,请执行以下操作:

$html = $this->load->view('stdHeader_view', TRUE); //add TRUE to the second parameter, to return the views content
$html .= '<div class="main">';
$html .= $this->load->view('foo_view', TRUE);
$html .= '</div>';
$html .= $this->load->view('stdFooter_view', TRUE);
$this->output->set_output($html); //ends the controller and shows $html as output
$html=$this->load->view('stdHeader\u view',TRUE)//将TRUE添加到第二个参数,以返回视图内容
$html.='';
$html.=$this->load->view('foo_view',TRUE);
$html.='';
$html.=$this->load->view('stdFooter\u view',TRUE);
$this->output->set_output($html)//结束控制器并将$html显示为输出

我认为这是一件完全合理的事情:)无论如何,你的最后一行间接地让我找到了答案,那就是使用
$this->output->append_output()
代替
echo
$html = $this->load->view('stdHeader_view', TRUE); //add TRUE to the second parameter, to return the views content
$html .= '<div class="main">';
$html .= $this->load->view('foo_view', TRUE);
$html .= '</div>';
$html .= $this->load->view('stdFooter_view', TRUE);
$this->output->set_output($html); //ends the controller and shows $html as output