Codeigniter 2.20 – Making your own home page

Back to CodeIgniter Tutorials

Now that  you have learned how to install codeigniter, it would be prefereable to replace the default codeigniter welcome page by something that we have made. By the end of this tutorial, when you will visit localhost/yourapp you will be presented with your own home page instead of the the default codeigniter Welcome page.

Install Codeigniter

First install Codeigniter. And make sure that you get the following page when you go to localhost/yourapp

Codeigniter installing xampp

Now we can get started.

Setting custom controller (which is first loaded)

In codeigniter, when you visit www.yourapp.com, a default controller is run by the server. This can be customized by editing a config file. This file is located at

localhost/yourapp/application/config/routes.php

Open this file and look for the following line:

Replace this line with a line which points out to our own controller (which we will make shortly)

We have just told codeigniter to point to our own controller instead of the default welcome controller which calls the welcome_message view. If you visit your website nowcodeigniter will try to access homecontroller but that does not exist yet. Lets make one!

Creating our controller

  1. Go to localhost/yourapp/application/controllers/
  2. Create a new file named homecontroller.php
  3. Add the following code in this file and the save it.

You have just created a controller which is pointing towards the view homepage. Lets create a view to finish the ritual.

Creating our View

  1. Go to localhost/yourapp/application/views/
  2. Create a new file named homepage.php
  3. Add the some HTML code to it like a paragraph. Maybe mention a Hello World!

You have just created a view which has our Hello World. Now you can use CSS styling to create more detailed websites.

 Lets test it

  1. Go to localhost/yourapp in your browser.
  2. You will see your new page/view 😀

Congratulations!

You have not only learnt how to install codeigniter, but also learnt how to set it up and make your own home page. In the next step, we will learn how to manage assets in codeigniter such as png, jpg, mp3, js, css, etc files.

Back to CodeIgniter Tutorials

Liked it? Take a second to support codeonion on Patreon!

Leave a Reply

Your email address will not be published.