Creating My First CodeIgniter App.
I'm using CodeIgniter version 2.1.0, the latest version by the time of writing. When I Googled for CodeIgniter tutorials, I found several pages, unfortunately, most were for versions earlier than 2.1.0. Unfortunately, codes from earlier versions does not fully work on 2.1.0. So I have to make some modifications in order to make it work.
My First CodeIgniter App.
I started with the very basic (and undying) "Hello World!" app. As I have mentioned in my previous post (Before Creating My First CodeIgniter Application), we need to created to pages, a controller page and a view page.
The Expected Output
The expected output would be:
Image 1: The Hello World Output.
1. The Controller Page.
Refer to Before Creating My First CodeIgniter Application for my explanation on controllers.
I created the file hello.php and saved it in the controllers folder. Again, I'm using NetbeansIDE to edit my html and php files.
Image 2: hello.php
2. The Views Page
I created then the you_view.php which simply displays 'Hello World!' and saved it in the views folder.
Image 3: you_view.php
Disecting the hello.php :
Line 2 is the class - which is the controller- named Hello.
Line 5 is the function named world ; which is the method.
Line 8 tells code igniter to load the page named you_view.php (indicated in view("you_view") which is saved in views folder.
The URL is: localhost/index.php/hello/world
Which means:
Next, I will modify this first application and explore the uses of variables and arguments in CodeIgniter.
Before I forget, something has to be done with that index.php.
Acknowledgement : I adopted this from Phpeveryday.com. However the examples there are for earlier versions of CodeIgniter.
The codes that are posted and will be posted here works on CodeIgniter 2.1.0.
I'm using CodeIgniter version 2.1.0, the latest version by the time of writing. When I Googled for CodeIgniter tutorials, I found several pages, unfortunately, most were for versions earlier than 2.1.0. Unfortunately, codes from earlier versions does not fully work on 2.1.0. So I have to make some modifications in order to make it work.
My First CodeIgniter App.
I started with the very basic (and undying) "Hello World!" app. As I have mentioned in my previous post (Before Creating My First CodeIgniter Application), we need to created to pages, a controller page and a view page.
The Expected Output
The expected output would be:
Image 1: The Hello World Output.
Take note of the URL. After the file index.php "/hello/world" which looks different compared to regular HTML URL (something like: localhost/hello/world/index.php - of course this means you have subfolders named hello and world. More of this later)
1. The Controller Page.
Refer to Before Creating My First CodeIgniter Application for my explanation on controllers.
I created the file hello.php and saved it in the controllers folder. Again, I'm using NetbeansIDE to edit my html and php files.
Image 2: hello.php
2. The Views Page
I created then the you_view.php which simply displays 'Hello World!' and saved it in the views folder.
Image 3: you_view.php
Disecting the hello.php :
Line 2 is the class - which is the controller- named Hello.
Line 5 is the function named world ; which is the method.
Line 8 tells code igniter to load the page named you_view.php (indicated in view("you_view") which is saved in views folder.
The URL is: localhost/index.php/hello/world
Which means:
- the hello after index.php is the name of the controller
- and the world after that is the method.
For now, you might be wondering why is it needed to create two pages just to display the words "Hello World!". It doesn't seem to make sense at all when you can do it in one line of pure HTML page.
The purpose of using CodeIgniter however is not to create static pages, but dynamic pages and ultimately web applications.
The purpose of using CodeIgniter however is not to create static pages, but dynamic pages and ultimately web applications.
As I continue to explore CodeIgniter, I will document it here. By sharing what I discover, hopefully you will learn as well.
Next, I will modify this first application and explore the uses of variables and arguments in CodeIgniter.
Before I forget, something has to be done with that index.php.
Acknowledgement : I adopted this from Phpeveryday.com. However the examples there are for earlier versions of CodeIgniter.
The codes that are posted and will be posted here works on CodeIgniter 2.1.0.



Comments
Post a Comment