Codeigniter App Tutorial
Lesson 2 of 10 · Codeigniter App Part 2 – Installation and Configuration · IT & Software
Codeigniter App Part 2 – Installation and Configuration
alright so in this video we're going to download install and configure codeigniter we'll do some configuration but we probably won't get it get to all
of it in this video because there's quite a bit that needs to be done to set it up correctly we want to have SEO friendly URLs so we get to create a dot htaccess file we want to link our
database we want to include our all our autoloaders so there's quite a bit to be done to get the the optimal setting alright so you want to do is go to ellis lab comm slash CodeIgniter
and just click on the green download button alright so look so now I have the zip file open which has an application folder a system folder and a user guide folder all right
so what we want to do now is create the folder on the server where we want coding idea to run and like i said i'm using xampp if you're using xampp then the default location of your server
folder is in your c drive and then xampp and then htdocs alright so this is where you want to create the folder my installation I have it in my Dropbox folder so if I go to my Dropbox I have
my in htdocs' folder just so I can access it on multiple machines which I would suggest that you do as well alright and in this directory we have a my to-do folder so I'm going to
create a folder actually you know what I want it to be named my to do so I'm just gonna look just say my to do old and then I'm gonna create this folder and call it like to
do all right so if we open that up we want to drag all our files into that folder and if you're not using xampp and you're using just a host or you have your own server just upload it to
whatever folder you want for your application all right so now we have the the files in the htdocs bowl there and the first thing I want to do is get rid of this user guide and it's basically
just the documentation and you can find the same info on the CodeIgniter website so there's really no sense in having this so I'm gonna get rid of that all right and the next thing I want to do is
we have two folders application system system we don't touch it has all the core libraries things like that all the core helpers we don't want to touch anything in that folder we do want to
touch things in the application folder this is where we'll be storing our controllers models and views and we will do our configurations you can see there's quite a bit of configuration
files here for security reasons you don't you don't have to but I like to change the names of these directories so I'm actually going to rename this just app and I'm gonna rename this just sis
sys and you can change it to whatever you want but if you change it make sure that you open up this index.php file all right so I'm going to open up sublime
text which I'm using as a code editor you can use whatever you'd like sublime text is free and it's it's it's pretty nice so I'm going to add a project folder and I'm just gonna select that
code igniter folder I mean I'm sorry that my to-do folder which I have in my Dropbox folder in actually in my htdocs folder all right so now I have my my structure
here so I'll minimize that and what we need to do since we rename these folders is open up the core index.php file and if we scroll down if you take a look at this we can we can set different
environments if you've ever used rails or are something like that then you probably probably seen this and you can add different functionality for different environments for example the
development the development environment we're showing all errors all right because we want to be able to debug if we're in the production environment then we're setting ever reporting to zero all
right so you can set different things depending on which witch you're in which environment you're in all right so this is where we want to change the names so the system folder we renamed to sis and
then the application we renamed to app all right so so let's save that do a ctrl s and let's go ahead and visit that directory so localhost / my to do
nope not like to do CI alright so this is the default welcome page when you install codeigniter and it's basically a controller called welcome which has a model a welcome
model and a welcome view alright so if we go and look in the file structure and app an app there's a welcome controller and let's see actually it doesn't have a model and then the view is just this
welcome message view and this is what we're seeing here we have some inline CSS here and then just the message that you see what we want to do now is we want to set our base URL all right so
that would be in the config and in config dot PHP alright so we have two things here we have a base URL which is going to be for us is going to be localhost / might to do all right
that'll be the base URL and we have a default index page which is index dot PHP alright so we also have in our routes file we have the default controller set as the Welcome controller
and since what the Welcome controller is set to the default that's what we see when we don't have anything on the end of this alright we don't have a controller in our URL but if we go to
controller I mean I'm sorry my to do slash welcome we don't see it and that's because we need our index page so index.php slash welcome alright so as it is now when we create a controller say
we created a control called pages if we wanted to visit that's that view we would have to do index dot PHP slash pages and we don't want that we want to be able to just to slash and then our
controller all right and if you don't understand that what we have in here is going to call this controller so slim since we have slash welcome it's going to call
this controller here all right which then loads the view which we see down here this welcome message all right so what I want to do is get rid of that I want to be able to go to this URL in
right now as it is we need to do the index.php so what we need to do is we need to create an HT HT access file and we want to create that in our root directory so I'm going to go ahead and
open up our folder structure here and we want to create I'm just going to right click and create a new document and we're gonna call it dot HT access all right so let's windows sometimes has an
issue with this because it doesn't have an extension I think we can do it through sublime text through the editor let's see new text document rename dot h t XS alright
so that let us do it so do it through your arm through your code editor if you have to couldn't find this item alright good so we have our thought htaccess file if you
have to you can open up FileZilla and and log in to your website and create it there alright so we want to grab that htaccess file alright so actually that's not the one we want you want to make
sure that you get the one in the root because if you look in the app directory it has one as well in the system directory we don't want to touch those alright we want only the one in the root
so I'm going to close that up and we want this one which should be blank and what I'm going to do is just paste some some content in here some code that'll interact with our server and what its
gonna do is it's gonna route everything through the index dot PHP file and it's gonna make it so that people cannot browse like they can't browse to our website folders through the browser the
only thing that's gonna be public that the browser will be able to access is the index dot PHP file and then things like images CSS stuff that we need to be public
alright robots.txt things like that alright so we need this to be able to use nice URLs without the index dot PHP so let's save that alright and if we go back here and we try to reload this now
we have we don't need to use that index dot PHP alright so that's how you enable SEO URLs with CodeIgniter alright so the next thing we want to do is connect our database oh I'm sorry we
need to fill in we want to go back to that config dot PHP file and the base URL usually we would put localhost / my to do alright so that is perfectly fine but this isn't dynamic if we decide to
move this this app to a new domain then we have to re-enter something here so what I do is put in something dynamic where it can automatically find the URL using superglobals so let me just grab
something and paste it in alright so I'm just gonna get rid of this and paste this in alright and this is going to grab our domain through the server superglobal through HTTP host and then
the directory name we can get through the script name right so this is going to equal the same thing and if you move this site or this app to a new domain it's automatically going to configure it
all right so I do this on all my codeigniter apps and now what we want to do is since we enabled SEO URLs and we don't need that index dot PHP in the URL you want to just get rid of this just
set this to nothing alright and let's see there's a bunch of things you can do if you want URL suffixes if you want it to look like this dot HTML you can do that language settings I don't think
there's anything that we need to do here oh actually we do alright so if you're going to be using the session class which we are because we're going to have a login system then you want to set an
encryption key and this can be anything you want all right so I'll just put it one two three four but you want something with more security than one two three four all right
and then let's see down here this looks fine all right so that's all we have to do with this so let's save the config dot PHP file and next we want to open up the
database file and we want to insert our info here all right so our username was root password I think I have just right here simple password and the name of the database which let's say we named it new
to do all right so we want to put that in the database name and we we're not we're not restricted to MySQL we can also use other databases
postgrads or something like that but by default we have the MySQL driver so that's fine and that's it for the database so let's save that still make sure everything's working all right so
let's see we want to configure the autoloaders so if we go to auto load duck PHP and what this does is makes it so that you don't have to manually load certain aspects of your site or your
apps such as packages libraries helpers config files language files and models so anything you want to use you want to add in the proper array here and one thing that we definitely need is the
database library if we're going to connect to a database we need that so we're going to place that in here so all we need to do is database all right so we're going to be using a few libraries
here I think yeah we want the session library as well all right so database in session and we want to use the form validation as well and if you want to know more about these
libraries I encourage you to go to the coding on our site and go to the documentation and you'll find everything you need that's another reason I really like code igniters everything is well
documented in my opinion now helpers are basically just functions their files with functions they don't have a class they don't have anything they're just functions you can include alright and
there we can make our own helpers but there's a few core helpers that we want to use one is the URL helper we also want the form helper and we want the HTML helper okay
so that should be all we need for now we will auto load some models when we get to that but for now we can just save this all right let's make sure everything's
working all right so that we basically have a complete coordinator installation that has been configured all right so in the next video what we'll be doing is creating a new
controller in replacing the Welcome controller and we'll look at that all right so thanks for watching and I'll see you in the next video
We will download and install Codeigniter. We will setup configurations for SEF URLs, link our database and define our base url
The full source code is at – https://github.com/bradtraversy/mytodo_ci