Try Tuts+ Premium, Get Cash Back!
CodeIgniter From Scratch: Day 1
videos

CodeIgniter From Scratch: Day 1

This entry is part 1 of 17 in the CodeIgniter From Scratch Session
Next »

After numerous requests, today we are launching a new screencast series on Nettuts+ that will focus exclusively on the CodeIgniter PHP framework. Over the course of about 10 videos, I’ll teach you exactly how to use this framework. Ultimately, we’ll work our way up to building a custom CMS. Without further ado, here’s day one!

Day 1


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

    thank you so much for tutorials ;)

  • Icetea

    This collection isnt working… I cant open the videos… the flash cant load the content. Anyone can help me?

    • luis

      hi! I opened the videos usually, can be a problem with your flash.

  • Ben

    Thanks Jeffrey this is a great tutorial.
    For anyone that is following this with the latest CodeIgniter (as of this writing version 2.1.2), you will have to extend CI_Controller and CI_Model instead of just Controller and Model. Also in the database.php file in the config folder make sure to set $db[‘default’][‘db_debug’] = false. Lost about two hours chasing these bugs down. Hope this helps.

    • Nadav

      Really really helps. Thank you.

    • http://www.valodustudija.lv Roberts

      Thanks, helped to solve my misunderstanding ;)

    • http://jsdecena.me Jeff

      Cool! I was also puzzled why I get error 500 creating a controller. Thanks for reminding! ^^

    • Opeyemi

      I actually followed the tutorial and appended ‘CI_’ to the controller and the model, but i could only display the last or second title of the ‘test’ table. if I use this code ”
      < ? php foreach($records as $row){
      echo $row-> title; }
      ? >

      It displays the two titles on a single row(i mean side by side).

    • http://twitter.com/horsebones Leke

      This is where youtube’s automations would come in handy.

    • Richard Steve

      Thanks friend, I appreciate it !!!

  • http://www.web-plus.cz Jiri

    Great tutorial.
    @Ben Thanks for your comment, it saved me some time. I also had to set in autoload.php this to load the DB library $autoload['libraries'] = array(‘database’);

  • Jacob

    Hey @ben, thanks for your comment, that saved me some time as well!
    Can you just explain why I had to make this change:
    $db[‘default’][‘db_debug’] = false;

    What does setting that to false do?

  • http://www.siyastoan.com Stoan

    Hey, The video doesn’t load on the page? can we get a different url if possible or any other help? Thank you

  • Roberto

    Wow, great tutorial! From this one tutorial, I already understand the concept of Code Igniter.
    Thank you!

  • saniya

    great tutorial for the beginners like me.. thank u so much jeffery..

  • Eyal

    Excellent tutorial! Thank you a bunch!
    Two small suggestions:
    1. Close all other programs prior to recording a lesson.
    2. Decide on var names beforehand (especially pages, tables).
    Thanks again and I am on my way to the next lesson! :-)

  • Opeyemi

    Thank you so much for this video. I have a problem please, i followed your examples but can only display the last title in my database. It only displayed the last title when i removed this ,It gave this error when it was there.
    ” A PHP Error was encountered

    Severity: Notice

    Message: Use of undefined constant t_endforeach – assumed ‘t_endforeach’

    Filename: views/home.php

    Line Number: 15″.

    Thanks for your time.

    • Opeyemi

      I actually followed the tutorial and appended ‘CI_’ to the controller and the model, but i could only display the last or second title of the ‘test’ table.

      if I use this code below

      < ? php foreach($records as $row){
      echo $row-> title; }
      ? > ”

      It will display the two titles on a single row(i mean side by side)

      Kindly help please. Thanks.

  • Prasann

    Getting error in common.php

    Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\htdocs\ci\system\codeigniter\Common.php on line 130

    Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\htdocs\ci\system\codeigniter\Common.php on line 136

    A PHP Error was encountered
    Severity: 8192

    Message: Function set_magic_quotes_runtime() is deprecated

    Filename: codeigniter/CodeIgniter.php

    Line Number: 60

  • http://www.codesamurai.de Carlos Bolanos

    such a melancholy, with this screencasts i learned to writte code, and still follow Jeffrey Way, through the years, dude!! you have created jobs for so many people, you must be proud!

    well at least me xD

  • JW

    Just wanted to give you a kudos for the tutorials! You explained every bit and piece and what each does which really helps a newbie. Sometimes videos tell you to type something but doesn’t explain what each word (code) does. Some people need to learn the literal use in laymen terms. You did an awesome job making it easy for anyone to understand. Thanks Again!

  • Arc

    Nice tutorial … thank you very much .. :)

  • http://www.targetweb.gr Peter

    Thanks for this great tutorial! Jeffrey, you definitely are the best.

  • darren

    please help

    i have added the site_model.php and altered the site.php as per turtorial but am getting an error:
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined property: Site::$db

    Filename: core/Model.php

    Line Number: 51

    Fatal error: Call to a member function get() on a non-object in /Applications/MAMP/htdocs/CodeI/application/models/site_model.php on line 7

    I have configured the autoload.php and the database.php files. any ideas?

    code for site.php
    load->database(‘ci_series’);
    $this->load->model(‘site_model’);
    $data['records']=$this->site_model->getAll();// create new data array which stores the called method getAll

    $this->load->View(‘home’);// loads view( the web page, passing it the data array
    }

    }

    ?>

    db->get(‘test’); // connect to db select all in test

    if ($q->num_rows > 0){
    foreach ($q->result() as $row){ // for each store in $q as$row
    $data[] = $row;
    }
    return $data;
    }
    }

    }

    ?>

    thanks

  • Dave

    Hi,
    so I’m doing the tutorial and I typed this into the controller:

    function index() {
    $data['myValue'] = “some string”;
    $this->load->view(‘home’);

    }

    and then I put in this into the views page:

    but I get the following error:

    A PHP Error was encountered

    Severity: Notice

    Message: Undefined variable: myValue

    Filename: views/home.php

    Line Number: 10

  • Dave

    Hi,
    sorry I’ll try that again:

    so I’m doing the tutorial and I typed this into the controller:

    function index() {
    $data['myValue'] = “some string”;
    $this->load->view(‘home’);
    }

    and then I put in this into the views page:

    <php echo $myValue; >

    but I get the following error:

    A PHP Error was encountered
    Severity: Notice
    Message: Undefined variable: myValue
    Filename: views/home.php
    Line Number: 10

    • i3oges

      you are not passing $data into your load->view(),
      it should be $this->load->view(‘home’, $data);

  • Dave

    SORRY,

    I’ve just seen my mistake, I forgot to add , $data

  • Gaurav Kanojiya

    Hi….
    I am in some trouble here.
    I followed your video but still at the end i am getting database connection error. I have gone through several posts regarding this error and even tried the fixes mentioned there. But the error remains there. So its a request from my side, if u have little time to go through my code then I will paste that here. I am not able to try other videos of your awesome tutorial on whole internet. Pleaseeee :(

    • Gaurav Kanojiya

      Ok….by mistake i have written database password to ‘root’, but i hv not given any password to it. but now I am getting a blank screen….why is it so?????

  • Peter

    Awesome tutorial, thanks!!

  • nagender

    Thank you very much ,i understood clearlly.

  • Arka

    Awesome tutorial…Thank you very much…

  • Anthony Bliss

    Spent 4 hours hitting my head against a wall trying to do this exact thing before finding this video! Life saver.

    Now going to stay up the rest of the night watching the rest <3

    One issue I have is that the videos are not iPad friendly, I wanted to use that as the video screen whilst I code!

  • Niels V

    Wow man, thanks great beginner tutorial.

  • http://twitter.com/aldrenterante AldrenRealesTerante

    Awesome! Thanks!

  • http://www.facebook.com/profile.php?id=100004166224922 Omar Abdirahman

    Exactly what I needed to understand CodeIgniter. Thank you Jeffrey

  • Kennedy KK

    Awesome. Only had to do a few changes since am using v2.1.2. Thanks.

  • aper

    Nice tut, i searched houres for this.

    But, can you please do a new CI tutorial using CI 2.1.3?
    I think many people would appreciate that.

    • http://www.gamefans.com/ Jeremy Davis

      I certainly would

    • http://twitter.com/horsebones Leke

      I’m new to CI. Is there a big difference between the latest version and 1.7?

      • Infoget

        Constructor is also changed:

        function __construct()
        {
        parent::__construct();

        $this->load->model(‘SOME_VALUE’);

        ….

        }

  • Nasik Mohammed

    Great Tuitorial

  • sivahari

    Great Tut thus far, works well even for ci version 2.1.3

    the only difference so far is when creating the Controller and Model classes which needs the CI_ prefix after extends

  • Ehsan

    Thank You .. it was great introduction

  • Sharif

    Great tutorial

  • munz

    man i loooooooooooooooooooooooooove uuuuuuuuuuuuuuuuuuuuuuuuuuu

  • Carol

    Hello ,Actually it’s my first time to learn codeigniter , now I’m facing a problem at 6.37 min in your video I am trying to open http://localhost/ci/index.php/site but it gives me

    404 Page Not Found ! what’s the problem! Thanks in advance

    • christy
      • Carol

        Actually I found the solution by replacing Controller to CI_Controller , Model to CI_Model :) as I have downloaded the latest version of codeIgniter , Thanks for the great tutorial :)

      • derrick

        i also could not open the base url . In eclipse, when i run after editing site.php to print hello world, nothing opens in the browser . I manually typed http://localhost/ci/index.php/site and it did not work either.

  • rajib123i

    hello there. i m new here. i have download the source code. but i did not found any .sql file or any other database to import. thanks.

  • http://www.facebook.com/rengarajan.g Rengarajan Gopalakrishnan

    How to connect more than 2 DB with CI?

  • ecko

    This tut is brilliant, why? Because you do really know how to explain things, and that’s why I am sure I will learn something. Thank you

  • Shadi

    About Removing The Index.php from the url when you are working on multiple projects which use Rewrite_mod it may do a conflict so easy copy the .htaccess into Code Igniter folder And Write this

    # Do not remove this line, otherwise mod_rewrite rules will stop working Just this

    RewriteBase /CodeIgniter_2.1.3(Or What Ever You call the File)/

    RewriteEngine on

    # Hide the application and system directories by redirecting the request to index.php or you can use the rules provided in the tutorial

    RewriteRule ^(application|system|.svn) index.php/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ index.php/$1 [QSA,L]

  • Dinishika

    This is a great beginning..thank you

  • imran

    nice tutorial

  • Parag

    thanks alot

  • rambideunt

    thanks for the tutorials. really useful for a first timer like me

  • Pratik Sawant

    Awesome tutorial, great way to start learning codeigniter, i loved it

  • tenpin

    hi my name is Andy Tierney I’m from the UK i’m 46 and new to codeighter it is being used as part of a modal assignment for uni

    i have a little under standing of what u are saying but u are using a mac i think so u are using a program called mamp pro what is this is this an equivalent to file zila a file transfer or is there some thing better out there for windows that is free iand would be better out there to use please could you help my email is sensi0007@yahoo.co.uk

    i’d like to say that the vidio i have seen so far would be very useful

    many thanks andy tierney

  • http://www.facebook.com/Sagar.S.Shinde Sagar Subhash Shinde

    Awesome Tutorial.
    Thanks a lot for this. I have been working on Core php and wanted someone to teach me CI.
    Thumbs Up

  • Fatma

    i have problem can someone help me ? i run appserv then i put my files in this path
    C:AppServwww/ci
    then i call my files bu use this url
    localhost/index.php/site

    but there is error

    Not Found

    The requested URL /index.php/site was not found on this server.

    Apache/2.2.8 (Win32) PHP/5.2.6 Server at localhost Port 80

    how can i solve this?

  • vinit

    thanks sir…..

    session was nice…..

  • Maede

    very good, and complete tutorial. It was what I wanted and searched! thank you very much!

  • FoxtrotSierra

    I’m having an issue right away. FYI, I am new to CI and PHP… I may be a lost cause. I have my documents in the website cloud.(dreamhost)
    I am able to manipulate them using Aptana.

    So here is the issue.(Please forgive me) Literally starting out using “site.php” I’m having an issue where “Controller” is not being recognized by Aptana.

    Here is what I have.

    <?php

    class Site extends Controller {
    function index() {
    echo "hello world";
    }
    }

    Here is what I get.|:
    Fatal error: Class 'Controller' not found in /home/etaladmin/cedarcreekradio.com/application/controllers/Site.php on line 2

    I've changed the Controller file permissions but still no luck.

    Any thoughts?

    Thank you!