tightened wording

World Wide Web Server 2012-07-04 16:05:03 -07:00
parent 9cc4b62b24
commit 075c85f343

@ -1,14 +1,17 @@
This code started life as an experiment in auto-loading views. I needed to be able to serve up already-existing HTML and PHP pages inside a CI context. This is how I did it with a minimum of fuss.
Would you like to serve up already-existing HTML and PHP pages inside a CI context?
Migrate a site to CI perhaps? This is how I did it with a minimum of fuss.
I wanted to be able to skip writing a controller method for every static page I wanted in my site. So I used _remap() to handle incoming URIs. The controller first checks if there is a controller method anywhere in the child or parent class. If there is not a method, it checks the filesystem for a matching view file. If there is a matching view file, then it loads it through the normal CI load->view() method.
One brute force way to migrate a site to CI is to write a controller method for every static page. But, if you are using CI already, then you probably like to find efficient ways rather than brute force ways.
So, it lets you put static pages in the views directory and your controller can load them inside a CI context without re-writing them or specifically coding a controller for each page. But, it also helps you migrate your existing site so that it progressively gets more CI-like.
Instead of mapping pages to controllers by hand, this code uses _remap() to handle incoming URIs. It uses a base controller that you extend. The base controller first checks if there is a controller method anywhere in the child or parent class. If there is not a controller method, it checks the filesystem for a matching view file. If there is a matching view file, then it loads it through the normal CI load->view() method. If there is no view file, you get the normal CI 404 error.
In the grand scheme, it lets you “drop in” a fully functional static (or dynamic) existing website into the views directory of a new CI install and have it work inside a CI context (controllers, models, and views, etc…). Then, when you are ready to start adding dynamic stuff/overriding the static pages, you just add a child controller and methods in that controller. The methods take precedence over the auto-loading of static view files.
Drop this base controller in place with a "skeleton" child class (optional but recommended) and you can put <em>static pages in the views directory</em>. Your controller will load them as if they were view files - inside a CI context - without re-writing them or specifically coding a controller for each page. Migrate your existing site in one fell swoop. Then you can piece out the functionality by adding controller methods so that it progressively gets more CI-like.
For each view file you want to stop auto-loading, just write a controller method that has the same name - it will take precedence.
You “drop in” a fully functional static (or dynamic) existing website into the views directory of a new CI install and have it work inside a CI context (controllers, models, and views, etc…). When you are ready to start adding dynamic stuff/overriding the static pages, you just add methods to the child controller. The methods take precedence over the auto-loading of static view files.
This is a parent/child controller combination to help you migrate html/php sites. supports nested views and (when enabled in CI config.php file) GET queries.
For each view file you want to stop auto-loading, just write a controller method that has the same name - it will take precedence. It's that simple.
This is a parent/child controller combination to help you migrate html/php sites. It supports nested views and (when enabled in CI config.php file) even GET queries.
Base controller - the parent class
[code]&lt;?php