简体   繁体   English

Codeigniter查看和回声

[英]Codeigniter View and echo

I have a function that which process the side bar of a web page in codeigniter. 我有一个函数,用于处理codeigniter中网页的侧栏。

as follows : 如下 :

function process_sidebar()
{
$this->load->view("first_access"); // ------------(1)
$this->load->view("second_access");// --------------(2)
echo "Here i want to show some data after loading view second_access"; //pls note here --(3)

$this->load->view("third_access"); // --------------------(4)
$this->load->view("fourth_access"); //-------------------------(5)

}

Please check the order numbers,but the problem is codeigniter not keeping the order. 请检查订单号,但问题是codeigniter没有保留订单。

it rendering the view last and showing the echo part first.. 它最后渲染视图并首先显示echo部分..

how can i overcome this ? 我怎么能克服这个?

Thank you. 谢谢。

You'll want to append_output() rather than echo : 你想要append_output()而不是echo

<?php
function process_sidebar()
{
    $this->load->view("first_access"); // ------------(1)
    $this->load->view("second_access");// --------------(2)
    $this->output->append_output("Here i want to show some data after loading view second_access"); //pls note here --(3)
    $this->load->view("third_access"); // --------------------(4)
    $this->load->view("fourth_access"); //-------------------------(5)
}

That's how view works in CodeIgniter, it doesn't get displayed immediately but gets buffered instead and displayed together later. 这就是视图在CodeIgniter中的工作原理,它不会立即显示,而是被缓冲而不是以后一起显示。 To overcome, if the text you want to display in between is static, make it part of the 2nd or 3rd view. 要克服,如果要在其间显示的文本是静态的,请将其作为第2或第3视图的一部分。 Otherwise, make it a variable of 2nd or 3rd view, and pass the text as view variable. 否则,将其设为第2或第3个视图的变量,并将文本作为视图变量传递。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM