Home >Backend Development >PHP Tutorial >How to generate static pages with CodeIgniter, codeigniter generates static_PHP tutorial
The example in this article describes the method of CodeIgniter generating static pages. Share it with everyone for your reference, the details are as follows:
Now let’s develop how to make the CI framework generate static pages. Post the code directly below:
$this->output->get_output();
Using this method, you can get the data to be output, save it, and keep it for use (when we build news websites, we often need to generate static HTML files).
$string = $this->output->get_output(); $this->load->helper('file'); write_file('./lianglong_codeigniter.html', $string);
For example, the page we want to output is to load the data after a certain view, then we will
$this->load->view('welcome_lianglong);
Join later
$this->output->get_output();
And give the value to a variable such as $lianglong to store it. Then use the write_file auxiliary function in CI's FILE to generate the file you want, as in the following example
function sc(){ $this->load->helper('file'); $this->load->view('welcome_message'); $lianglong=$this->output->get_output(); if ( !write_file('./lianglongfile.html', $lianglong)) { echo 'Unable to write the file'; } else { echo 'File written!'; } }
or:
function sc(){ $this->load->helper('file'); $liangdong=$this->load->view('welcome_message',$data,true); if ( !write_file('./lianglongfile.html', $lianglong)) { echo 'Unable to write the file'; } else { echo 'File written!'; } }
Readers who are interested in more CodeIgniter related content can check out the special topics of this site: "codeigniter introductory tutorial", "CI (CodeIgniter) framework advanced tutorial", "php excellent development framework summary", "ThinkPHP introductory tutorial", "Summary of Common Methods in ThinkPHP", "Introduction Tutorial on Zend FrameWork Framework", "Introduction Tutorial on PHP Object-Oriented Programming", "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of Common PHP Database Operation Skills"
I hope this article will be helpful to everyone’s PHP program design based on the CodeIgniter framework.