Diary of a Codeigniter Site Day 2

Planning, Planning, Planning...

Okay, so I've spent another hour or two tweaking some HTML layouts. I have the index.html looking way I want, and an 'article' (I preferefer the term 'article' over 'post') page looking the way I want with all the essential elements. Some might think differently, but as a newb at MVC, I find it important to be very clear on the HTML structure of my pages so that when it comes to doing the CodeIgniter Views (the V in MVC), I can simply view source of my pages, copy the bits I need, and incorporate them into the view files. These HTML pages won't be part of the final site, but I keep them for reference as I move along.

My index.html page has a header (which also contains a navigation bar), a content area where I will display article synopsis for perhaps the last 5 articles, a sidebar with linkage to articles, as well as a links area, and a search functionality.

My diaryday1.html page will contain an individual article with a byline having the author name (me) and date, the article body, links to next/previous articles, a comment form, and comments. The sidebar will be removed.

There's a few other pages in mind (Articles, Other Stuff, Contact) but I'll tackle those later, as I'm now feeling comfortable with the overall flow of things.

Installing CodeIgniter

This probably the easiest part of the process. I'm going to follow some of the recommended 'best practises' for CI installation. CI is very flexible as far as that goes. After you download and extract CI, you will have a folder containing just a few files and folders:

  • application
  • index.php
  • license.txt
  • system
  • user_guide

You should have a quick read of license.txt, and the user_guide folder is indispensable, but they don't need to part of your installation. You just need the system folder, the application folder, and the index.php

You can read more about the install of CI on their site, but the options to install are so flexible that it may be confusing to the new user. It might not be clear, for intance that you can have one system folder powering multiple CI applications. Additionally, the system folder can be almost anywhere on your webservers filesystem. And best practises say that it is desirable to have the system folder (even the application folder) somewhere on the webserver where prying eyes can't access it. In fact, the only file that has to in a publicly accessible directory is the index.php file.So the question is, where is the best place to put it?

This site is being hosted on a 1and1 shared server. Here's how I structure things:

  • In my 1and1 Control Panel, is create a folder named osxsuxdotcom
  • Inside the the osxsuxdotcom folder I create a folder named www
  • I upload my CI system and application folders to the osxsuxdotcom folder
  • I upload the CI index.php file to the www folder
  • In my domains Control Panel, I specify /osxsuxdotcom/www as the root folder for the domain www.osxsux.com

The only file accessible to the web surfing public is index.php (in a bit we'll also put an images, css, and js folder there). My system and application folders are protected from prying eyes and nasty hackers. All that remains is to let CodeIgniter know where I put the system and application folders, and we do that in index.php. For even more fun, we can rename the system and application folders - I'm going to call it system CI172, so it's clear to me that Im running CodeIgniter version 1.7.2, and the application folder to osxsuxApp, so its clear to me that this is my app folder for this site. So it looks something like this:

  • osxsuxdotcom/
    • /C172
    • /osxsuxApp
    • /www
      • index.php

Now we just need to configure index.php Because we have moved system and application out of the publicly accessable webrot, you will need the absolute paths to your install directory. The easiest way to get that is the create a phpinfo() file on your webroot an look in the output, in the Environment section, for your absolute path. On 1and1 it looks something like '/kunden/homepages/99/d12345678/htdocs/'. So, open your index.php, there are only 2 lines to modify:

$system_folder = "/kunden/homepages/99/d12345678/htdocs/osxsuxdotcom/CI172";
$application_folder = "/kunden/homepages/99/d12345678/htdocs/osxsuxdotcom/osxsuxApp";

Navigate to your www.yourwebsite.com/index.php, and you should see the classic CodeIgniter welcome screen. Moving forward, you never need to make another change to your index.php, and you should (generally) never modify the contents of your system folder. The only folder you wll work with is your application folder. You have the basis of a reasonably secure site, and, in the future, if CodeIgniter releases an updated version, you can simply upload the new system folder, modify your index.php to point at it, if everthing works, great, if the new version breaks something, just point back at the earlier system folder.

Moving forward

I was suppose get the template library runing today, but that will have to wait. Writing this diary is taking more time than planned, but is a useful exercise. So tommorrow, I'll tackle the template library and begin serving these currently static pages dynamically.

Your Comment
(Not displayed)
 Prove You're Human


QIMoYk <a href="http://ypudgukpvquc.com/">ypudgukpvquc</a>, [url=http://husorpykibxm.com/]husorpykibxm[/url], [link=http://hqyvuxxuxofm.com/]hqyvuxxuxofm[/link], http://pwjfgzsjcvyr.com/

UC0PYW <a href="http://xaksshnyeqpt.com/">xaksshnyeqpt</a>, [url=http://zlsnolhrrtci.com/]zlsnolhrrtci[/url], [link=http://gqjueamvginc.com/]gqjueamvginc[/link], http://ikiyipucwxoh.com/

What a wonderful article! You must be very smart