Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
Python and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Lua, etc
CodeIgniter - an excellent PHP framework with an easy start point

Frameworks are such a valuable tool to help you write a web application - they provide the common structure that you need in most applications in addition to the web server itself, and into which you can write your own application specific code. But there's often a steep learning curve with a framework, and a bloat which means that you end up wit something that works, but works far less efficiently than code written without a framework.

Under PHP, I've done quite a bit of work over the last few months with the Zend Framework, but flavour is this month from a training viewpoint seems to be CodeIgniter by Ellis Labs. It's an easy download, unpack it to get it working and "Hello World" can be implemented very quickly with a template of your web page filled in by the controller in just a few file changes. I'm impressed!

  -bash-4.1$ diff -r vanilla/public_html/ public_html
  Only in public_html/application/controllers: mycontroller.php
  Only in public_html/application/views: pages
  Only in public_html/application/views: templates
  Only in public_html: .htaccess
  Only in public_html: index.html

As with any system that's documented online, the EllisLabs / manaual pages have - even at the beginning - lots of ifs, buts can caveats, so I thought I would include the final content of the six files I added (nothing changed) to make this work.

My first example produces:

Training on CodeIgnitor

Here are the file contents:

index.html - to provide a home page outside the CodeIgniter tests

  <head><title>Consultations dot org dot uk</title></head>
  <body><h1>Currently a test site!</h1>
  In use by <a href=http://www.wellho.net>Well House Consultants</a> for our training courses

.htaccess - to reroute everything else to CodeIgniter

  RewriteEngine on
  # Route home page to "locked out" special front page
  RewriteRule ^index.htm index.html [L]
  RewriteRule ^$ index.html [L]
  # Send all running pages except index.php, robots.txt and the user guide to index.php
  RewriteCond $1 !^(index\.php|images|robots\.txt|user_guide)
  RewriteRule ^(.*)$ /index.php/$1 [L]

application/controllers/mycontroller.php - to provide a first controller

  class Mycontroller extends CI_Controller {
    public function view($page = 'home') {
    $data = array('title' => "showing CodeIgniter");
    $this->load->view('templates/header', $data);
  //    $this->load->view('pages/'.$page, $data);
    $this->load->view('pages/main', $data);
     $this->load->view('templates/footer', $data);

application/views/pages/main.php - to provide the view called up by that controller

  [[Content here]]

application/views/templates/header.php - to provide the header used by all views

    <title><?= $title ?> - Well House Tutorial</title>
    <h1>Teaching you to write excellent PHP - <?= $title ?></h1>
  <i>This is the header</i>
  <hr />

application/views/templates/footer.php - to provide the footer used by all views

  <hr /><i>This is the footer</i><br /><br />
  <?php date_default_timezone_set('Europe/London'); ?>
  <a href=http://www.wellho.net>Well House Consultants</a>
  - <strong>©<?= date("Y") ?></strong>

Frameworks become more and more important in PHP development and in my "best practise" module on all PHP courses I now talk about Router / Model / View / Controller, and I can cove off examples as required. At present, CodeIgniter is just a formal quick demo - but I'm happy to be kept talking about it after the course, and to include it in private courses.

Source code links for the files used above:

Controller - [here]
Main view - [here]
Header - [here]
Footer - [here]
.htaccess for routing changes - [here]
dummy front page - [here]
(written 2013-04-06, updated 2013-04-13)

Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
H321 - PHP - CodeIgniter
  [4114] Teaching CodeIgniter - MVC and PHP - (2013-06-12)
  [4062] Sessions, forms and validation in CodeIgniter - early examples - (2013-04-13)
  [4053] Frameworks - learning through exploring and understanding data sources - (2013-03-27)

Back to
Curl and curling from PHP
Previous and next
Horse's mouth home
Forward to
Seamless, integrated IT - we have a long way to go!
Some other Articles
Apache httpd - a robust, open source web server
Backups by crossover between network centres - setting up automatic scp transfers
Seamless, integrated IT - we have a long way to go!
CodeIgniter - an excellent PHP framework with an easy start point
Curl and curling from PHP
The highs and lows of customer service - Cheltenham
stdClass in PHP - using an object rather than an associative array
An overpractical test of our backup strategy!
Using web services to access you data - JSON and RESTful services
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page

This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2019: 404 The Spa • Melksham, Wiltshire • United Kingdom • SN12 6QL
PH: 01225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/4060_Cod ... point.html • PAGE BUILT: Sat May 27 16:49:10 2017 • BUILD SYSTEM: WomanWithCat