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
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:
$route['default_controller'] = "welcome";
Replace this line with a line which points out to our own controller (which we will make shortly)
$route['default_controller'] = "homecontroller";
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 now, codeigniter will try to access homecontroller but that does not exist yet. Lets make one!
Creating our controller
- Go to localhost/yourapp/application/controllers/
- Create a new file named homecontroller.php
- Add the following code in this file and the save it.
public function index() { $this->load->helper('url'); $this->load->view('homepage'); }
You have just created a controller which is pointing towards the view homepage. Lets create a view to finish the ritual.
Creating our View
- Go to localhost/yourapp/application/views/
- Create a new file named homepage.php
- 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
- Go to localhost/yourapp in your browser.
- 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.
2 responses to “Codeigniter 2.20 – Making your own home page”
Hey
I have experience in running wordpress applications over IIS and it is very simple. After that I thought lets host the codeigniter application over IIS after that I found the error
Please find below file:
https://dipoletechi.com/blog-post/how-to-setup-codeigniter-application-on-iis/
Thanks
Your services are impressive.