CodeIgniter Basics

Everything You Need to Get Started With CodeIgniter

Tutorial Details
  • Difficulty: Beginner
  • Technology: PHP

CodeIgniter is a web application framework for PHP. It enables developers to build web applications faster, and it offers many helpful code libraries and helpers which speed up tedious tasks in PHP. CodeIgniter is based on a modular design; meaning that you can implement specific libraries at your discretion – which adds to the speed of the framework. This tutorial will attempt to show you the basics of setting up the framework, including how to build a basic hello world application that uses the MVC approach.


Why a Framework?

Why a Framework?

Frameworks allow for structure in developing applications by providing reusable classes and functions which can reduce development time significantly. Some downsides to frameworks are that they provide unwanted classes, adding code bloat which makes the app harder to navigate.


Why CodeIgniter?

CodeIgniter Basics

CodeIgniter is a very light, well performing framework. While, it is perfect for a beginner (because
of the small learning curve), it’s also perfect for large and demanding web applications. CodeIgniter is developed by EllisLab and has thorough, easy to understand
documentation. Below is a list of reasons of what makes CodeIgniter a smart framework to use?

  • Small footprint with exceptional performance
  • MVC approach to development (although it is very loosely based which allows for flexibility)
  • Generates search engine friendly clean URLs
  • Easily extensible
  • Runs on both PHP 4 (4.3.2+) and 5
  • Support for most major databases including MySQL (4.1+), MySQLi, MS SQL, Postgres, Oracle, SQLite,
    and ODBC.
  • Application security is a focus
  • Easy caching operations
  • Many libraries and helpers to help you with complex operations such as email, image manipulation,
    form validation, file uploading, sessions, multilingual apps and creating apis for your app
  • Most libraries are only loaded when needed which cuts back on resources needed

Why MVC?

MVC

For starters, MVC stands for Model, View, Controller. It is a programing pattern used in developing
web apps. This pattern isolates the user interface and backend (i.e. database interaction from each other. A successful
implementation of this lets developers modify their user interface or backend with out affecting
the other. MVC also increases the flexibly of an app by being able to resuse models or views over
again). Below is a description of MVC.

  • Model: The model deals with the raw data and database interaction and will contain functions
    like adding records to a database or selecting specific database records. In CI the model
    component is not required and can be included in the controller.
  • View: The view deals with displaying the data and interface controls to the user with.
    In CI the view could be a web page, rss feed, ajax data or any other “page”.
  • Controller: The controller acts as the in between of view and model and, as the name suggests,
    it controls what is sent to the view from the model. In CI, the controller is also the place to load libraries and helpers.

An example of a MVC approach would be for a contact form.

  1. The user interacts with the view by filling in a form and submitting it.
  2. The controller receives the POST data from the form, the controller sends this data to the model
    which updates in the database.
  3. The model then sends the result of the database to the controller.
  4. This result is updated in the view and displayed to the user.

This may sound like alot of work to do. But, trust me; when you’re working with a large application, being able to reuse models or views saves a great deal of time.


Step 1: Downloading CodeIgniter

Too start off you will need to download CodeIgniter and upload it to your server. Point your browser
to http://www.codeigniter.com/ and
click the large download button. For this tutorial we are using version 1.70.


Step 2: Installing and Exploring CodeIgniter

Once you have downloaded CodeIgniter, all you need to do is unzip it, and rename the “CodeIgniter_1.7.0″ folder to
either the application name or, in this case, “ci” and upload it to your PHP and MySQL enabled server.
Now that its on your server, I’ll explain what all the folders and files are for:

  • The system folder stores all the files which make CI work.
    • The application folder is almost identical to the contents of the system folder
      this is so the user can have files that are particular to that application, for example if a
      user only wanted to load a helper in one application he would place it in the system/application/helpers folder
      instead of the system/helpers folder.

      • The config folder stores all the config files relevant to the application. Which
        includes information on what libaries the application should auto load and database details.
      • The controllers folder stores all the controllers for the application.
      • The errors folder stores all the template error pages for the application. When
        an error occurs the error page is generated from one of these templates.
      • The helpers folder stores all the helpers which are specific to your application.
      • The hooks folder is for hooks which modify the functioning of CI’s core files,
        hooks should only be used by advanced users of CI
      • The language folder stores lines of text which can be loaded through the language
        library to create multilingual sites.
      • The libraries folder stores all the libraries which are specific to your application.
      • The models folder stores all the models for the application.
      • The views folder stores all the views for the application.
    • The cache folder stores all the caches generated by the caching library.
    • The codeigniter folder stores all the internals which make CI work.
    • The database folder stores all the database drivers and class which enable you to
      connect to database.
    • The fonts folder stores all the fonts which can be used by the image manipulation library.
    • The helpers folder stores all of CI’s core helpers but you can place your own helpers
      in here which can be accessed by all of your applications.
    • The language folder stores all of CI’s core language files which its libaries and helpers
      use. You can also put your own language folders which can accessed by all of your applications.
    • The libaries folder stores all of CI’s core libaries but you can place your own libraries
      in here which can be accessed by all of your applications
    • The logs folder stores all of the logs generated by CI.
    • The plugin folder stores all of the plugins which you can use. Plugins are almost identical
      to helpers, plugins are functions intended to be shared by the community.
    • The scaffolding folder stores all the files which make the scaffolding class work.
      Scaffolding provides a convenient CRUD like interface to access information in your database
      during development.
  • The user_guide houses the user guide to CI.
  • The index.php file is the bit that does all the CI magic it also lets the you change the
    name of the system and application folders.

Step 3: Configuring CodeIgniter

Getting CI up and running is rather simple. Most of it requires you to edit a few configuration
files.

You need to setup CI to point to the right base URL of the app. To do this, open up system/application/config/config.php and
edit the base_url array item to point to your server and CI folder.

$config['base_url'] = "http://localhost/ci/";

Step 4: Testing CodeIgniter

We’ll do a quick test to see if CI is up and running properly. Go to http://localhost/ci/ and you
should see the following.


Step 5: Configuring CodeIgniter Cont.

If you’re up and running, we should finish the configuration. We are starting to configure it specifically for our new helloworld app. If you want to use a database with your application, (which in this tutorial we do.) open up system/application/config/database.php and set the following array items to there corresponding values. This code connects to a MySQL
database called “helloworld” on a localhost with the username “root”, and the password, “root”.

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "root";
$db['default']['database'] = "helloworld";
$db['default']['dbdriver'] = "mysql";

Additionally, since we will be using the database quite a bit, we want it to auto load so that we don’t
have to specifically load it each time we connect. Open the system/application/config/autoload.php file
and add ‘database’ to the autoload libaries array.

$autoload['libraries'] = array('database');

Currently, the CI setup will have a default controller called “welcome.php”; you can find this in the system/application/controllers folder. For this tutorial, delete it and open your system/application/config/routes.php file. Change the default array item to point to the “helloworld” controller.

 $route['default_controller'] = "Helloworld"

CI also has a view file that we do not need. Open up the system/application/view/ folder
and delete the welcome_message.php file.


Step 6: Create the Helloworld Database

As this isn’t really a tutorial on MySQL, I’ll keep this section as short as possible. Create a database called “helloworld” and
run the following SQL through phpMyAdmin (or similar MySQL client).

CREATE TABLE `data` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(255) NOT NULL,
  `text` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

INSERT INTO `data` (`id`, `title`, `text`) VALUES(1, 'Hello World!', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla 
sapien eros, lacinia eu, consectetur vel, dignissim et, massa. Praesent suscipit nunc vitae neque. Duis a ipsum. Nunc a erat. Praesent 
nec libero. Phasellus lobortis, velit sed pharetra imperdiet, justo ipsum facilisis arcu, in eleifend elit nulla sit amet tellus. 
Pellentesque molestie dui lacinia nulla. Sed vitae arcu at nisl sodales ultricies. Etiam mi ligula, consequat eget, elementum sed, 
vulputate in, augue. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;');

Step 7: Create the Helloworld Model

Models are optional in CI, but it’s considered best practice to use them. They are just PHP classes that contain
functions which work with information from the database. Go
ahead and make a helloworld_model.php file
in the system/application/models folder.
In this file, create a Helloworld_model class, Helloworld_model construct and a function called getData.

In the getData function we are
going to use Active Record database functions which speed up database development times when working
with CI and databases. Essentially, they are simplified functions to create queries.

<?php
class Helloworld_model extends Model {

    function Helloworld_model()
    {
        // Call the Model constructor
        parent::Model();
    }
    
    function getData()
		{
			//Query the data table for every record and row
			$query = $this->db->get('data');
			
			if ($query->num_rows() > 0)
			{
				//show_error('Database is empty!');
			}else{
				return $query->result();
			}
		}

}
?>

Step 8: Create the Helloworld Controller

Let’s create a controller that will display the view, and load the model. That way, when
you go to the address http://localhost/ci/index.php/helloworld/, you will see the data from the database.
In the folder system/application/controllers, create a file called helloworld.php.
In this new file, we’ll create a class which has the same name as the file.

Within this class, you need to create a function called “index”. This is the function that will be
displayed when no other is provided – e.g. when http://localhost/ci/index.php/helloworld/ is
visited. If, for example, we created a function called foo, we could find this as http://localhost/ci/index.php/helloworld/foo/.

The key thing to remember is how CI structures its URLs; e.g http://host/codeignitordirectory/index.php/class/function.

In the controller index function, we need to load the model, query the database, and pass this queried
data to the view. To load any resources into CI e.g. libraries,
helpers, views, or, models, we use the load class. After we have loaded the model, we can access it through
its model name and the particular function. To pass data to a view we need to assign it to an array
item and pass the array – which recreates the array items as a variable in the view file.

<?php
	class Helloworld extends Controller{
		function index()
		{
			$this->load->model('helloworld_model');

			$data['result'] = $this->helloworld_model->getData();
			$data['page_title'] = "CI Hello World App!";

			$this->load->view('helloworld_view',$data);
	    }
	}
?>

If we visited http://localhost/ci/index.php/helloworld/ now, it wouldn’t work; this is because the view file does not exist.


Step 9: Create the Helloworld View

The view file is what the user sees and interacts with, it could be a segment of a page, or the whole page. You can pass an array of variables to the view through the second argument
of the load model function. To make the view for our tutorial, create a new file called helloworld_view.php in the system/application/view folder. Next, we just need to create our normal html, head
and body elements, and then a header and paragraph for the information from the database. To display all
the records received from the database, we put it in a “foreach” loop
which loops through all the elements.

<html>
	<head>
		<title><?=$page_title?></title>
	</head>
	<body>
		<?php foreach($result as $row):?>
		<h3><?=$row->title?></h3>
		<p><?=$row->text?></p>
		<br />
		<?php endforeach;?>
	</body>
</html>

You may have noticed that we are using php alternative syntax, this provides an convenient and time
saving way to write echo statements.


Step 10: Ta-da and Some Extras

When you visit “http://localhost/ci/index.php/helloworld/”, you
should see something similar to this.

But we aren’t done yet. There are a few things you can do to improve your CodeIgniter experience -
like removing that annoying index.php bit out of the URL. You can accomplish this task by creating a .htaccess file in the root folder, and adding the following code.

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ ci/index.php/$1 [L]
        

You’ll also need to open up the config.php file in system/application/config/ and edit the index_page array item to a blank string.

$config['index_page'] = ""; 

Another nifty trick is to turn on CI’s ability to parse PHP alternative syntax if its
not enabled by the server. To do this, open up the same file as before, system/application/config/config.php, and set the rewrite_short_tags array item to TRUE.

$config['rewrite_short_tags'] = TRUE;

I hope all goes well! Look forward to seeing more CodeIgniter tutorials from me in the future.

  • Subscribe to the NETTUTS RSS Feed for more daily web development tuts and articles.


Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • Miky

    I’m working my way out to try and make this work in CI 2.0, but I simply can’t. It gives me an internal server error . I made the changes that I read in the comments, i also have mod_rewrite on in Apache and still nothing.. could anyone help me please? thanks !

  • Ronnie

    The model is wrong.
    ——————————————————–
    if ($query->num_rows() > 0)
    {
    //show_error(‘Database is empty!’);
    }
    ——————————————————–
    it should be: if ($query->num_rows() < 1)

  • Sankalp

    Fatal error: Class ‘Controller’ not found in C:\xampp\htdocs\ci\application\controllers\helloworld.php on line 2

    class Helloworld extends Controller{
    function index()
    {
    $this->load->model(‘helloworld_model’);
    $data['result'] = $this->helloworld_model->getData();
    //$data['result'] = $this->helloworld_model-> getData();
    $data['page_title'] = “CI Hello World App!”;

    $this->load->view(‘helloworld_view’,$data);
    }
    }

  • Sankalp

    class Helloworld extends Controller{
    function index()
    {
    $this->load->model(‘helloworld_model’);
    $data['result'] = $this->helloworld_model->getData();
    //$data['result'] = $this->helloworld_model-> getData();
    $data['page_title'] = “CI Hello World App!”;

    $this->load->view(‘helloworld_view’,$data);
    }
    }

    Fatal error: Class ‘Controller’ not found in C:\xampp\htdocs\ci\application\controllers\helloworld.php on line 2

  • iwan

    Parse error: syntax error, unexpected ‘<', expecting T_STRING or T_VARIABLE or '{' or '$' in D:\xampp\htdocs\CodeIgniter\application\controllers\helloworld.php on line 7

    what is this mens?

  • Maverick

    Using standard php classes everyone would have finished already without all these weird errors while using frameworks to try to speed up things, just learn to program for real..!. lol

  • vahida

    ( ! ) Parse error: parse error, expecting `T_STRING’ or `T_VARIABLE’ or `’{” or `’$” in D:\wamp\www\codeigniter1\application\controllers\helloworld.php on line 7
    Call Stack
    # Time Memory Function Location
    1 0.0001 92744 {main}( ) ..\index.php:0
    2 0.0006 95944 require_once( ‘D:\wamp\www\codeigniter1\system\core\CodeIgniter.php’ ) ..\index.php:202

    • http://www.weblarge.com Somnath Bhattacharjee

      @vahida , the code mentioned in this most need some changes to work properly,

      1) in controller, helloworld.php replace

      “$data['result'] = $this->helloworld_model->getData(); ”

      with

      ” $data['result'] = $this->helloworld_model->getData(); ”

      2) again in helloworld.php

      replace

      “class Helloworld extends Controller{ ”

      with

      “class Helloworld extends CI_Controller{ ”

      3) In Model, helloworld_model.php

      replace

      “class Helloworld_model extends Model { ”

      with

      “class Helloworld_model extends CI_Model { ”

      4)Again in helloworld_model.php

      replace

      “// Call the Model constructor
      parent::Model(); ”

      with

      “// Call the Model constructor
      parent::__construct(); ”

      5)Again (the most important one!) in helloworld_model.php

      Replace the function segment inside the function getData()

      “if ($query->num_rows() > 0)
      {
      //show_error(‘Database is empty!’);
      }else{
      return $query->result();
      } ”

      WITH

      “if ($query->num_rows() > 0)
      {
      return $query->result();
      }else{
      //show_error(‘Database is empty!’);
      } ”

      Hope these changes will fix all the issues, :)

      • max

        Hello, I only get out:
        title?>
        text?>

        after all the changes. How do I do with the view?
        Thanks

      • MrDMAdev

        Max -

        Unless you change $config['rewrite_short_tags'] = TRUE; in the config.php file, the code above for the view most likely won’t work properly.

        You need to change this above code:

        title?>
        text?>

        To:

        title?>
        text?>

        I added php in front of the question marks for the tag and the tag. Without adding the php part, your server (or codeigniter) assumes short tags = true. So, either change short tags to true in config.php or add the php as I did.

      • MrDMAdev

        Max -

        My last post is stripping out the formatting I used in my examples I wasn’t paying attention to the instructions to post code, so let me try again:

        Unless you change $config['rewrite_short_tags'] = TRUE; in the config.php file, the code above for the view most likely won’t work properly.
        You need to change this above code:

        <html&gt
        <head&gt
        <title&gt<?=$page_title?&gt</title&gt
        </head&gt
        <body&gt
        <?php foreach($result as $row):?&gt
        <h3&gt<?=$row-&gttitle?&gt</h3&gt
        <p&gt<?=$row-&gttext?&gt</p&gt
        <br /&gt
        <?php endforeach;?&gt
        </body&gt
        </html&gt

        To:

        <html&gt
        <head&gt
        <title&gt<?=$page_title?&gt</title&gt
        </head&gt
        <body&gt
        <?php foreach($result as $row):?&gt
        <h3&gt<php?=$row-&gttitle?&gt</h3&gt
        <p&gt<php?=$row-&gttext?&gt</p&gt
        <br /&gt
        <?php endforeach;?&gt
        </body&gt
        </html&gt

        I added php in front of the question marks for the tag and the tag. Without adding the php part, your server (or codeigniter) assumes short tags = true. So, either change short tags to true in config.php or add the php as I did.

      • Jack Smith

        Thanks! Somnath this code woked fine!!!!

      • Sun

        Do not showing exact result.I’m new in Codeigniter.Please help me….After complete the above code showing the below result on my local PC….

        Server error!

        The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

        If you think this is a server error, please contact the webmaster.
        Error 500
        localhost
        10/12/12 23:52:38
        Apache/2.2.9 (Win32) DAV/2 mod_ssl/2.2.9 OpenSSL/0.9.8i mod_autoindex_color PHP/5.2.6

      • Noah_Igniter

        hi….your contribution is really appreciated……iam new to CI, now iam going to write registration form…will u help me

    • MrDMAdev

      Max -

      Grrrrrr! The formatting still didn’t work right. Just add “php” in front of the question marks in the h3 and p tags.

    • http://bit.ly/ci-tutorial arunoda

      Here is a place you should look for best set of codeigniter tutorials -

      1. http://www.udemy.com/codeigniter-learn-it-correct/
      2. http://www.youtube.com/watch?v=aOtDzuyBqqM&list=PLA81C68F3BB3AE307

  • http://www.sijojose.in sijo

    First of all, thanks to tutplus for the wonderful tutorials.
    Its simple to learn and try out..

    Some problem arise during the time of compilation

    The working code is given below

    1. helloworld_model.php

    db->get(‘data’);
    if($query->num_rows() > 0)
    {
    return $query->result();

    }
    else {
    show_error(‘Database is empty’);
    }
    }
    }
    ?>

    2. helloworld.php

    load->model(‘helloworld_model’);
    $data['result'] = $this->helloworld_model->getData();
    //$data['result'] = $this->helloworld_model-> getData();
    $data['page_title']=”CI test appln”;
    $this->load->view(‘helloworld_view’,$data);
    }

    }

    ?>

    3.helloworl_view.php

    title?>
    text ?>

    thanks……

    • Manish

      Thanx.

      • Arun Panicker

        Thaks Mr Sijo…you solve my problem

  • Chuck

    Tutorial doesn’t work and is a waste of time. Instead of hacking around, why not specify that the tutorial is for version 1.x or 2.x and edit it accordingly with the correct code for one or the other.

    • golam mustafa

      There was some bugs. I able to execute.
      first in Helloworld_model and Helloworld(Controller) the super class will be CI_Model instead of Model and CI_Controller instead of Controller.

      The constructor call for Hello_world_model will be

      function __construct()
      {
      // Call the Model constructor
      parent::__construct();
      }

      rather than
      function Helloworld_model()
      {
      parent::Model();
      }

      Third there are some logical error in Helloworld_model() in line 15
      it should be if($query->num_rows()<=0)
      {
      show_error('Database is empty!");
      }

      Rather then, these , the tutorial is really helpful.
      Thanks!!

      • Raja MM

        Thanks for your updates.

  • Pradeep Sharma

    This tutorial is now outdated. New version of CI 2.x requires to prefix core classes with CI_. IT would be great if you can fix this.

    Thanks for a great tutorial. It was worth trying.

  • abdulqadir

    thanks for the tutorials
    the following errors occur when i run my helloworld program
    Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\ci\system\codeigniter\Common.php on line 130
    plzzzzzzz help me

  • http://vinayakkadolkar.orgfree.com Vinayak

    Change in halloWord_model.php
    IT WILL Work

    if ($query->num_rows() == 0)
    {
    show_error(‘Database is empty!’);
    }else{
    return $query->result();
    }

  • Loa

    I get the following error and there is nothing I can do with it:

    A PHP Error was encountered

    Severity: Warning

    Message: Invalid argument supplied for foreach()

    Filename: views/helloworld_view.php

    Line Number: 6

  • lol

    this tutorial is a waste of time……

  • http://www.sobkichu.com Arif Uddin

    Thanks, from your tutorial I can run CI for first time.

  • Pingback: CodeIgniter Beginner Tutorial 1–Configuring CodeIgniter | Data Integrated Entity

  • Pingback: Everything You Need to Get Started With CodeIgniter | Web Page Tutorials

  • Belisaurius

    This tutorial is a waste of time, and is why I will not sign up for the premium service which I was literally seconds way from buying, lucky I tried one of your tutorials first before I wasted my money.

    • corn

      really dude???? i bet if you have have an open minded approach and you will learn a lot from people

  • http://codyeding.com Cody

    @Loa: The “Invalid argument supplied for foreach()” error is a result of a mistake in the Helloworld Model (The logic on the if statement is incorrect).

    Line 15 reads:

    if ($query->num_rows() > 0)

    Which is wrong. This will return nothing for a database containing any records, which is the opposite of what it is supposed to do!

    It should read:

    if ($query->num_rows() == 0)

    This checks if there are no records. If there are records, it will successfully return the data so the foreach loop will work.

    Hope this helps anyone struggling with this.

    • Mayank

      Working very well, gr8 solution :)

  • http://www.bestfreewebservices.com Larry Curtis

    Wow, nice tutorial about basic codeigniter configuration. Thanks buddy, I can’t wait to start developing site using codeigniter.

  • http://mywebsuccess.biz Alex Hoyle

    I know that some of the code problems are because of codeignitor version differences, but seriously someone should rewrite this tutorial.

    Who proofread this part?
    $data['result'] = $this->helloworld_model->getData();

    It should be
    $data['result'] = $this->helloworld_model->getData();

  • Pingback: Everything You Need to Get Started With CodeIgniter « prakashmca007

  • arpi

    thanks Somnath

  • atul

    add more topics

  • http://5208100706.posterous.com/ Ah Wirayudha

    model

    db->get(“data”);
    //if($query->num_rows()>0)
    $query = $this->db->get(‘data’);

    if ($query->num_rows() > 0)
    {
    return $query->result();

    }
    else {
    //show_error(‘Database is empty’);
    }
    }
    }
    ?>

    controller

    load->model(“helloworld_model”);
    $data['result'] = $this->helloworld_model->getData();
    //$data['result'] = $this->helloworld_model-> getData();
    //$data['page_title']=”CI test appln”;
    $this->load->view(“helloworld_view”,$data);
    }

    }

    ?>

    it work… terima kasih…

  • http://about.me/malshan malshan

    Some parts should be updated for new versions of CI.
    helpful post.Thanks.

  • http://tecklead.blogspot.com napster

    helo ..I didn’t get the answer.I dont know more about this.am a beginner..please update the files..thanks ..

  • Pingback: User Registraion with CodeIgniter « joysana (java & php expt.)

  • http://www.localhost.com mohit

    thanks…….

  • http://net.tutsplus.com/tutorials/php/codeigniter-basics/ Ravindranath

    it’s nice but we want extra matter in this pdf

  • t3rmin41

    Belisaurius, this tutorial is not a waste of time, it’s not working smoothly from the first time because of differencies in version. The author mentioned above:

    For this tutorial we are using version 1.70.

    So if you use another version, no surprise it doesn’t get work from the first time. The comments left by other users are enough to figure out how to make it work in other version (I managed on CI 2.1.0 !) and if you don’t read them or don’t look for information, then it’s better forget about coding for you.

  • daniele

    but we can take the span in the php?????
    that is in the step 8 line 7..
    thanks for answer i’m baby developer!
    please rx!

  • http://www.computersneaker.com Mudasir Nazir

    I have found some problem with your conditional structure

    if($query->num_rows()>0)
    {
    echo $query->result();
    }
    else
    {
    show_error(‘table is empty’);
    }

    well over all it is fine.

  • Pingback: MVC, for beginners | Andrea Seepersad

  • Pingback: MVC, for beginners | Andrea Seepersad

  • suresh

    100000 like for this simply and best tutorial made e learn most of thing. Like to see some more tutorial based on codeigniter.

  • george5729

    This tutorial does not work for me?

  • Andy G

    Any chance in updating this CI tutorial? The folder structure has changed.

  • Pingback: Starting with CodeIgniter « What , Why , How

  • http://www.facebook.com/ashokmhrj Ashok Maharjan

    hey buddy nice tuts thanks..

  • sandeep

    not working…getting error like
    Fatal error: Class ‘Controller’ not found in C:wampwwwciapplicationcontrollershelloworld.php on line 2
    whats the problem?

    • T john peter

      Hi, put ‘CI_Controller’ instead of ‘Controller’..

    • Arun panicker

      Replace the Controller with CI_Controller

  • Guest

    In this code where we can see class controller?It is not working………!

    load->model(‘helloworld_model’);

    $data['result'] = $this->helloworld_model->getData();

    $data['page_title'] = “CI Hello World App!”;

    $this->load->view(‘helloworld_view’,$data);

    }

    }

    ?>

  • sandeep

    Im this code where we can see class controller..? It is not working…!
    load->model(‘helloworld_model’);

    $data['result'] = $this->helloworld_model->getData();

    $data['page_title'] = “CI Hello World App!”;

    $this->load->view(‘helloworld_view’,$data);
    }
    }
    ?>

  • ardiesta

    good.. great tutorial, thanks

  • http://darvishzadeh.com/ Sonny Darvishzadeh

    I liked it when you said models are optional. this is explaining to the bone with great summarising

  • Ankita

    Really great tutorial :)

    But it show Call to a member function get() on a non-object in /var/www/codeigniter/application/models/hello_model.php on line 18 error.

    For solving this I use

    function __construct()
    {
    // Call the Model constructor
    parent::__construct();
    $this->load->database();
    }
    in helloworld_model.php

  • GereltOd

    Your tutorial is full of Errors!

    1. Delete function Helloworld_model from model.
    2. Rename Extends to CI_Controllers, CI_Models.
    3. Switch IF statements in Model.

  • GereltOd

    Your tutorial is full of Errors!

    1. Delete function Helloworld_model from model.
    2. Rename Extends to CI_Controllers, CI_Models.
    3. Switch IF statements in Model.

  • Abraham

    Wow such a simple and straight forward steps to learn and creat first application with Codeigniter. Thank you 1000 times.

  • hi

    ryrty