Simple View Controller for beginners. |
First thing to post in this forum should be how to create a simple view which is the appearance of your web application. I had tried so many tutorials on Internet for making a MVC and always succeeded but when i try to make my own home page of site my myself i always failed.
The only thing that showed up is: "404 Page Not Found The page you requested was not found. " I just want a simple thing. When anyone open www.mywebsite.com my home page will be open. Is this necessary to make a model if there is no database work in needed? Now i tell you what i did myself to make my home page. 1. First of all i made a file 'index.php' in view folder (Simple HTML file). 2. I added a file 'index_controller.php' in controller folder. (see code below) Code: class Index_controller extends CI_Controller{ What more should i do to make my code working??
03-05-2015, 03:41 AM
(This post was last modified: 03-05-2015, 04:26 AM by Avenirer. Edit Reason: some additional info )
In the first place, you shouldn't name your controller Index_controller. Never.
But if you still want to name it that way, the way to access the controller would be http://localhost/index_controller Website: http://avenir.ro
03-05-2015, 04:19 AM
(This post was last modified: 03-05-2015, 04:20 AM by Vimal. Edit Reason: or you can set default controller to index in ) PHP Code: class Index extends CI_Controller{ Go to Yoursite.com/index.php/index or you can set default controller in application/config/route.php
My advice is roughly the same. Don't ever create a controller named Index.
Website: http://avenir.ro
I know you all maybe masterminds of codeigniter but here i am talking about a person who is a serious beginner. I had find my answer by myself which is "Route.php". This is the main problem in my complete code. No one told me that i have to add a line of code in "config/route.php" to make my link work. Without route.php all the coding is just a waste of time.
In application/config/routes.php:
PHP Code: $route['default_controller'] = 'home'; // 'welcome' is another popular choice Then add application/controllers/Home.php: PHP Code: <?php The index method in your home controller then becomes available at the following locations (assuming you have rewrite configured properly and index.php removed from your URLs): http://mysite.com/ http://mysite.com/home http://mysite.com/home/index
the advise to beginners should be - if you can see the CI welcome page - then next work through the tutorial that is in the CI manual.
and if you need to work on something quickly, just do it in the welcome controller and there is no other setup required. |
Welcome Guest, Not a member yet? Register Sign In |