Initial configuration

June 1st, 2010

When you start a new project, below are some configuration that you might need to change.

FORMAT: filename — what to change

  • index.php — change application folder name
  • application/config/database.php — change db username, password and db name
  • application/config/autoload.php — set library and helper to be autloaded. Some of common lib/helper – database, url, template(external lib)
  • application/config/routes.php — change default controller
  • application/config/config.php — change base url and index page name

Ease of Use

May 27th, 2010

As you already notice, the “/application/” folder are resides in the “/system/” folder. For some security reason (because in “/system/” folder contains all our back-end configuration and etc), and some recommendation from CI users, I suggest that you copy your “/application/” folder outside the “/system/” folder.

But, this is not the main point of my Ease of Use entry. The main item that i wanted to highlight to you are about your “/CSS/” and “/images/” folder. There are some minor discussion going in our room, discussing where should we put our 2 “most important” folder and files (in that folder).

At first, we decided to put it in the “/Views/” folder which are in the “/application/” folder.

The path of the folder are as such:

http://localhost/site/application/views/css/style.css
http://localhost/site/application/views/images/some_img.png

But, after googling around, and found some tutorial giving some nice lecturers, I decided to put both folders at the root folder. To put it simple, at the same level of your “/application/” and “/system/” folder.

Why I decide to put both folder in such manner?

The reason is, it is easier during the coding process, for us to fetch the, in example, the stylesheet (style.css). Instead of you need to access it through the path folder “/application/views/css/style.css“, you can just specify the path as “/css/style.css“.

1
2
3
4
5
6
7
//So, instead of using
$this->file(BASEPATH.'application/views/css/style.css');
 
//you can just use
$this->file(BASEPATH.'css/style.css');
 
//when you want to call for the files.

Or, if you wanted to call an image in your code, with the help of CI’s HTML_Helper , you can call the image using

1
<?php echo img(array('src' => 'images/logo.png', 'class' => 'some_class')); ?>

instead of

1
<?php echo img(array('src' =>'application/views/images/logo.png', 'class' => 'some_class')); ?>

At first, you don’t see it as a problem, just a little different in the folder’s path. But, as your code grew larger, your code will look messy and full of those paths. I don’t know about you, but i’ll get dizzy when it comes to debug something that is not well organized and messy. Pheww! Such a hassle to identify what i really need to take care of. :)

Also, if you are a web designer (like me), of course, once in a while, you will go through other sites to peek (or copy) their stylesheet (For God Sake, I do! :P ). So, you don’t want them to know the path of your folders resides(For some security reason, I guess). :)

Page template in CodeIgniter

May 27th, 2010

In normal PHP development, we usually made a template to be use for any other pages that has content. Usually the template page contains section like header, content and footer (this is default).

In CodeIgniter there is 3 way to do that, by using CodeIgniter’s built in parser, some external method and using external libraries made by community.

1. CodeIgniter’s built in parser

CodeIgniter’s aware of this problem and already made their solution by introducing template parser class. To use this class, simply load the library into your controller code:

1
$this->load->library('parser');

Suppose your template called template1.php and the contents of the template is like follows:

1
2
3
4
5
6
7
8
9
10
<html>
<head>
<title>{title}</title>
</head>
<body>
 
<h3>{heading_title}</h3>
<p>{body}</p>
</body>
</html>

Additional code in controllers to pass on template was:

1
2
3
4
$data = array(
            'title' => 'My Blog Title',
            'heading_title' => 'My Blog Heading'
            );

All data need to pass on template need to be inserted into an array with the key named exactly like those in curly brackets inside template page. Finally parse the template together with the array of data created.

1
$this->parser->parse('template1', $data);

2. Ask about PHP method

Ask about PHP shared their method of how to have a template with just using normal view in CodeIgniter. Their explanation was here.

3. External community library

Jérôme Jaglale had came out with library that really helpful. Further explanation are on his page. Downloadable copy of the library are also there.
Most Simple Template Library for CodeIgniter

Installing CodeIgniter

May 27th, 2010

Installing CI framework is very straight forward.

First you need PHP and web server install on your server/PC. For development on windows, you can download and install WAMP.

Then go to CI website to download latest framework.

Copy the whole folders/files to your web server root folder. For example in wamp, you can copy to c:\wamp\www and create a folder name codeigniter

Then straight away test it on web browser. Example http://localhost/codeigniter

It should work correctly and you will be guided by on screen help on where to go from there.

For online help go to CI user guide. You can also found the localhost help in http://localhost/codeigniter/user_guide (use the folder name you install it on)

Hello world!

May 27th, 2010

First message. No fancy stuff in here. All about CodeIgniter framework for us to refer as we learn and for the world to benefit from. Cheers