Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter object not found only the index function works

I am new to CodeIgniter, everything was going fine and well up until I found out that I can only make a call to the index() function.

I have setup the config.php, autoload.php and routes.php as expected.

on the config.php

$config['base_url'] = 'http://localhost/ci';
$config['index_page'] = '';

on the autoload.php

$autoload['helper'] = array('form','url');

on the routes.php

$route['default_controller'] = "site";

I have a controller named site

<?php

    class Site extends CI_Controller{

        function index(){
            $this->load->view('home');
        }

        function new_method(){
            $this->load->view('home2');
        }
    }
?>

I have to 2 files on the view folder with their HTML code, simply named home.php and home2.php

on home.php I have

<?php 
    echo form_open('site/new_method');
    echo form_submit('submit', 'call method'); 
    echo ('<br /><br />');
    echo anchor('site/new_method', 'call method');
    echo form_close();
?>

The index() loads, as results U get a button and a link but when I click I am given Object not found! Error 404

like image 370
immanuelx Avatar asked Nov 22 '25 15:11

immanuelx


2 Answers

Follow the steps that Furqan mentioned, but if that doesn't work, try this in your .htaccess file (in the root of your project):

RewriteEngine on
RewriteCond $1 !^(index\.php|assets|images|js|css|uploads|favicon.png)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$ ./index.php/$1 [L]
like image 101
Richard Lovell Avatar answered Nov 24 '25 06:11

Richard Lovell


  1. You can make this empty $config['base_url'] = '';
  2. Check .htaccess in root folder with index.php file
  3. Check mod_rewrite apache module is enabled

RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L]

like image 23
Furkat U. Avatar answered Nov 24 '25 06:11

Furkat U.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!