Welcome Guest, Not a member yet? Register   Sign In
Simple View Controller for beginners.
#1

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.
"
 Angry
I just want a simple thing. When anyone open www.mywebsite.com my home page will be open.  Blush

Is this necessary to make a model if there is no database work in needed?  Dodgy

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{
    public function __construct()
    {
        parent::__construct();
    }
    
    public function index()
    {
        $this->load->view('index');
    }
}

What more should i do to make my code working?? Huh
Reply
#2

(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
Reply
#3

(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{
    public function 
__construct()
    {
        
parent::__construct();
    }
    
    public function 
index()
    {
        
$this->load->view('index');
    }



Go to Yoursite.com/index.php/index

Smile

or you can set default controller in application/config/route.php
Reply
#4

My advice is roughly the same. Don't ever create a controller named Index.
Reply
#5

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.
Reply
#6

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

class Home extends MY_Controller
{
 
   public function __construct()
 
   {
 
       parent::__construct();

 
       // Load additional helpers and libraries; language file
 
   }

 
   public function index()
 
   {
 
       // Setup your index page
 
   }


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
Reply
#7

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB