codeigniter Object not found! 404 error

18,306

Maybe url is incorrect.

    http://localhost/projectfolder/index.php/controller/method

in ur case:

    http://localhost/yourprojectfolder/index.php/users/login

Replace "projectfolder", "controller", "method" with yours. Make sure your file name for Users Controller is "users.php"

Share:
18,306
user2637286
Author by

user2637286

Updated on June 04, 2022

Comments

  • user2637286
    user2637286 about 2 years

    hi everyone im new to php frameworks development at all, and i can't make this code run please help me im using xampp

    my welcome controller

    <?php
    
    class Welcome extends CI_Controller
    {
    
    public function index()
    {
    
        $this->load->view('home');
    
    }
    }
    

    home view

    <html>
    <head>
    <title>CTS - home</title>
    <style type="text/css">
    .auto-style1 {
        text-align: center;
    }
    </style>
    </head>
    
    <body bgcolor="#C0C0C0" style="height: 226px">
    
    <div class="auto-style1" style="height: 118px">
        <img alt="" height="126" src="<?php echo $this->config->item('base_url'); ?    >/IMG/YUC.png" style="float: left" width="147">
        <center><h1 style="height: 39px; width: 696px">Cooperative Training Management     System</h1></center>
    </div>
    <br>
    <hr>
    <div class="auto-style1">
        <a href="<?php echo site_url('') ?>users/login">
        <img alt="YUC Employee" height="410" src="<?php echo $this->config-    >item('base_url'); ?>/IMG/employee.png" width="139">
        </a>
        <img alt="trainer" height="410" src="<?php echo $this->config->item('base_url'); ?    >/IMG/Trainer.png" width="145">
        <a href="<?php echo site_url('') ?>users/login">
        <img alt="Student" height="410" src="<?php echo $this->config->item('base_url'); ?    >/IMG/student.png" width="129">
        </a>
        <h3>Employee&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp        ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Trainer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp    ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Student</h3>
    </div>
    <hr>
    <p align="right">Page generated in <strong>{elapsed_time}</strong> seconds</p>
    </body>
    </html>
    

    and this is the second controller users

    <?php
    
    class Users extends CI_Controller 
    {
    
        function login()
        {
            $data['error']=0;
            if($_POST){
                $this->load->model('user');
                $username=$this->input->post('username',ture);
                $password=$this->input->post('password',true);
                $user=$this->user->login($username,$password);
                if(!$user){
                    $data['error']=1;
                }else{
                    $this->session->set_userdata('userID',$user['userID']);
                    redirect(base_url().'home');
                }
            }
            $this->load->view('login');
    
        }
    
        function logout()
        {
            $this->session->sess_destory();
            redirect(base_url().'home');
        }
    }
    

    and this is the model user

    <?php
    
    class User extends CI_Model 
    {
    
        function __construct()
        {
            parent::__construct();
            $this->load->helper('url');  
        }
    
        function login($username,$password)
        {
    
            $where=array(
                            'username'=>$username,
                            'password'=>sha1($password)
                        );
            $this->db->select()->from('s_users')->where($where);
            $querh=$this->db->get();
            return $querh->first_row('array');
        }
    }
    

    and this is the login view

    <html>
    <head>
    <title>CTS - Login</title>
    <style type="text/css">
    .auto-style1 {
        text-align: center;
    }
    </style>
    </head>
    
    <body bgcolor="#C0C0C0" style="height: 98px">
    
    <div class="auto-style1" style="height: 118px">
        <img alt="" height="126" src="YUC.png" style="float: left" width="147">
        <center><h1 style="height: 113px; width: 696px">Cooperative Training Management     System</h1></center>
    </div>
    <br>
    <hr>
    <div class="auto-style1">
    
    <fieldset name="Group1">
        <legend align="left"><h1>Login</h1></legend>
        <?php if($error==1){ ?>
        <p>Your Username / Password did not match.</p>
        <? } ?>
        <form action="<?=base_url()?>users/login" method="post" style="height: 96px">
    
            <label>Username </label><input name="Text1" type="text">
            <br>
            <label>Password</label> <input name="Password1" type="password">
            <br><br>
            <input name="Login" style="width: 96px" type="submit" value="Login">
    
        </form>
    
    </fieldset>
    </div>
    <hr>
    <p align="right">Page generated in <strong>{elapsed_time}</strong> seconds</p>
    </body>
    </html>
    

    .htaccess

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
    
        #Removes access to the system folder by users.
        #Additionally this will allow you to create a System.php controller,
        #previously this would not have been possible.
        #'system' can be replaced if you have renamed your system folder.
        RewriteCond %{REQUEST_URI} ^system.*
        RewriteRule ^(.*)$ /index.php?/$1 [L]
    
        #When your application folder isn't in the system folder
        #This snippet prevents user access to the application folder
        #Submitted by: Fabdrol
        #Rename 'application' to your applications folder name.
        RewriteCond %{REQUEST_URI} ^application.*
        RewriteRule ^(.*)$ /index.php?/$1 [L]
    
        #Checks to see if the user is attempting to access a valid file,
        #such as an image or css document, if this isn't true it sends the
        #request to index.php
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?/$1 [L]
    </IfModule>
    
    <IfModule !mod_rewrite.c>
        # If we don't have mod_rewrite installed, all 404's
        # can be sent to index.php, and everything works as normal.
        # Submitted by: ElliotHaughin
    
        ErrorDocument 404 /index.php
    </IfModule>
    
  • user2637286
    user2637286 almost 11 years
    mmmm not working my dear same thing with me i cant find any other error
  • user2637286
    user2637286 almost 11 years
    Object not found! The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error. If you think this is a server error, please contact the webmaster. Error 404 localhost Apache/2.4.4 (Win32) OpenSSL/0.9.8y PHP/5.4.16
  • user2637286
    user2637286 almost 11 years
    by the way the first controller works but when i try to move to users controller i cant
  • itsme
    itsme almost 11 years
    @user2637286 ok do you use .htaccess? can you post it please? can you also post your config/config.php and config/routes.php files please?
  • user2637286
    user2637286 almost 11 years
    the problem was index.php in the url see my .htaccess
  • itsme
    itsme almost 11 years
    @user2637286 ok understood, just follow my last directives you'll get no problems with. ;)