Home>

Now let's develop how to make the ci framework generate static pages.Directly post the code below:

$this->output->get_output ();

Using this method,You can get the data that will be output,And save it,Keep it for use (when we make a news type website,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 the data after loading a certain view.Then we are

$this->load->view ("welcome_lianglong);

Join later

$this->output->get_output ();

And store the value in a variable such as $lianglong.Then use the write_file helper function in ci's file,Generate the files i want,As 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!";
 }
}
php
  • Previous Problem with normal distribution sort of javascript array
  • Next Install php7 + php5 under nginx