CodeIgniter a method to generate a static page _php instance

Source: Internet
Author: User
Tags codeigniter zend framework

The example in this article describes how CodeIgniter generates a static page. Share to everyone for your reference, specific as follows:

Now let's develop how to let the CI framework generate static pages. The following direct code:

$this->output->get_output ();

Using this method, you can get the data you want to output, save it, and keep it used (when we do news type Web sites, 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 are going to output is the data that is going to load a view, then we

$this->load->view (' Welcome_lianglong);

Then join

$this->output->get_output ();

And the value to a variable such as $lianglong stored. Then use the Write_file auxiliary function in CI file to generate the file you 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! ';
 }
}

More interested in CodeIgniter related content readers can view the site topics: "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "PHP Excellent Development Framework Summary", "thinkphp Introductory Course", " Thinkphp Common Methods Summary, "Zend Framework Introduction Course", "PHP object-oriented Programming Introduction Course", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design based on CodeIgniter framework.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.