Recently I have been familiar with some principles of php running. generally, php calls the template file through the controller to display the page. at the same time, some variable values in the controller will also be assigned to the template file, I use template. php files are used as template files, so php's... recently I have been familiar with some principles of php running. generally, php calls the template file through the controller to display the page. at the same time, some variable values in the controller will also be assigned to the template file, I use template. php files are used as template files. Therefore, you can directly use the php syntax in the template file to display the assigned variables in the controller. By viewing the CI framework code, the system first enables ob_start, introduces the template file template. php, and returns ob_get_clean (), as shown below.
ob_start();include($_ci_path);$buffer = ob_get_contents();@ob_end_clean();return $buffer;
At the same time, I think the code principles of the company's internal framework are basically the same. now I want to know how to use a series of functions such as ob, it seems that only the include file can be assigned a value.
Reply content:
Recently I have been familiar with some principles of php running. generally, php calls the template file through the controller to display the page. at the same time, some variable values in the controller will also be assigned to the template file, I use template. php files are used as template files. Therefore, you can directly use the php syntax in the template file to display the assigned variables in the controller. By viewing the CI framework code, the system first enables ob_start, introduces the template file template. php, and returns ob_get_clean (), as shown below.
ob_start();include($_ci_path);$buffer = ob_get_contents();@ob_end_clean();return $buffer;
At the same time, I think the code principles of the company's internal framework are basically the same. now I want to know how to use a series of functions such as ob, it seems that only the include file can be assigned a value.
Function render ($ template, array $ var = array () {extract ($ var); // extract the variables in the array (here is your concern) ob_end_clean (); // disable the top-level output buffer content ob_start (); // start a new buffer require "$ template"; // load view $ view = ob_get_contents (); // Obtain the buffer content ob_end_clean (); // Close the buffer ob_start (); // start the new buffer and return $ view to the subsequent programs; // return the text, you can also directly output echo here}
The functions of the Ouba series are still very useful. you can see that after the controller calls the render rendering view, the HTML is obtained. you can write the HTML into a static file and cache it, or, it is very convenient to replace some things in HTML and output them.
echo render('index.php', $data);
The effect of the buffer zone is still quite large. For example, if you want to save the client information, or use the wrong sending file header informationheader
Orsetcookie
Impact
I can only understand that you don't understand what include is.