CodeIgniter is an open source web application framework built for PHP coders who want to develop a full-feature web application. It has libraries which help us to perform many tasks very easily. It works on the MVC Pattern.
Model–View–Controller (MVC) is a design pattern for computer user interfaces that divides an application into three areas of responsibility:
- the Model : the data structures that represent the application's state.
- the View : which observes the state and generates output to the users.
- the Controller : which translates user input into operations on the model.
Today I will be telling you how to start with CodeIgniter and the MVC Pattern. The example we will be taking is a basic Hello World Application. For this I will be using XAMPP Server, Eclipse/Netbeans (more Preferred) or any IDE and CodeIgniter 2.1.0.
To download XAMPP SERVER, Click Here.
To download Netbeans (with PHP support), Click Here.
To download CodeIgniter Framework, Click Here.
Lets Start
Open Netbeans, follow the steps :
* Click File -> New Project -> PHP -> PHP Application. And click next.
* Now change Project name (as HelloWorld) and the Source Folder to Xampp/htdocs/. Check the image below.
And after doing the above i.e. Giving Appt. Project name and finding the Xampp/htdocs/helloworld folder.
Click on next and then copy the line, http://localhost/your-project-name.
Now go to the unzipped CodeIgniter Folder and copy everything inside it and paste it to Xampp/htdocs/helloworld.
After that is done, go to netbeans and click on source and then open Application -> config.
Inside config.php change
$config['base_url'] = ''; TO
$config['base_url'] = 'http://localhost/your-project-name';
Now open application -> Controller and create a new php file in that, name it hello.php :
Next step, make a view. Create helloworld.php within application\views.
But before that, goto application -> config ->routes.php. Inside routes.php change the
$route['default_controller'] = "hello";
Now start Xampp server, in that start Apache Server. And then goto netbeans and run the project.
The application will run and the browser will display,
Hello.php :
<?php class Hello extends CI_Controller { public function __construct() { parent::__construct(); } public function index(){ $this->load->view('helloworld'); } } ?>
Next step, make a view. Create helloworld.php within application\views.
helloworld.php :
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Hello World App</title> </head> <body> <h1>Hello World!</h1> <div > <p>My First CodeIgniter Application. </div> </body> </html>
But before that, goto application -> config ->routes.php. Inside routes.php change the
$route['default_controller'] = "hello";
Now start Xampp server, in that start Apache Server. And then goto netbeans and run the project.
The application will run and the browser will display,
Great Post, Actually PHP is a beautiful source for developing a database driven web application, I love this post, thanks for spending your time for discussing about this topic.
ReplyDeleteRegards,
PHP Training Center in Chennai
ya it's best for start..
ReplyDeletehttp://ng4free.com/codeigniter-tutorial-hello-world-example-steps/
ReplyDeleteplease let me know how to run a project in codeigniter step by step.
ReplyDeletei need to know the url that should be typed in the search bar.
Great Information... Thanks for sharing your views about this article... it is very useful to me...
ReplyDeletePHP Training in chennai