Welcome Guest, Not a member yet? Register   Sign In
Convert Dynamic pages to static html page using codeigniter.
#1

[eluser]Rahul gamit[/eluser]
I have a page that pulls the content from a MySQL db,When I add new content (via a form in the admin area) I want the site to generate a static HTML copy of the PHP page. This way the page only needs to call the db when I update the site rather than everytime somebody loads the page.

Has anyone any pointers on how to go about this?
#2

[eluser]n0xie[/eluser]
How about just caching the output?
#3

[eluser]Rok Biderman[/eluser]
While I agree that n0xie has a point, here is a way to do it.

Code:
function write_to_file()
    {
        $this->load->helper('file');
        $this->load->model('yourmodelname');
        $data['example'] = $this->yourmodelname->yourmethodname();
        $datatofile = $this->load->view('someview', $data, TRUE);
            if ( ! write_file('./static/somefilename.htm', $datatofile))
                {echo 'Unable to write the file';}
            else
                {echo 'File written!';}
    }

As you see, you can pass a view into a variable with 3rd argument set to true. Then it's easy to put whatever you want into the view, kinda like this.

Code:
<html>
<head>
<title>Sometitle</title>
</head>
<body>

<?php
echo $example->id . "<br>\n";
echo $example->firstname . "<br>\n";
echo $example->lastname . "<br>\n";
echo $example->adress . "<br>\n";
echo $example->phone1 . "<br>\n";
echo $example->phone2 . "<br>\n";
echo $example->city . "<br>\n";
?&gt;
&lt;/body&gt;
&lt;/html&gt;

I did this because I couldn't find it in forums and I think it could come in hand once in a while. For let's say a blog that's expected to have heavy traffic, this would be benefitial. However I see a lot of new users trying to extend the classes and use the framework in very unusual ways, before they even got a regular crud working, many times trying to incorporate bad (since past good habits are not problematic) habits they acquired in the past. That way, CI will soon become another nightmare for them. Just my 2c.
#4

[eluser]Rahul gamit[/eluser]
Hey thanks it is working...
thank you so much :-)




Theme © iAndrew 2016 - Forum software by © MyBB