Home > Backend Development > PHP Tutorial > How to generate static pages with CodeIgniter, codeigniter generates static_PHP tutorial

How to generate static pages with CodeIgniter, codeigniter generates static_PHP tutorial

WBOY
Release: 2016-07-12 08:52:14
Original
797 people have browsed it

CodeIgniter generates static pages, codeigniter generates static

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();

Copy after login
Copy after login

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);

Copy after login

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);

Copy after login

Join later

$this->output->get_output();

Copy after login
Copy after login

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!';
 }
}

Copy after login

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!';
 }
}

Copy after login

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1127866.htmlTechArticleCodeIgniter generates static pages, codeigniter generates static pages. The example of this article describes the method of CodeIgniter generating static pages. Share it with everyone for your reference, the details are as follows: Now we...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template