3

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

BenMorel
  • 34,448
  • 50
  • 182
  • 322
immanuelx
  • 35
  • 1
  • 1
  • 5

5 Answers5

7

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]
Richard Lovell
  • 848
  • 10
  • 18
2
  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]

Furkat U.
  • 431
  • 5
  • 20
  • thanx i have went to apache and i still don't understand what is going on with the .htaccess. The problem was that i had gone and removerd the index.php on the congfig like this ($config['index_page'] = '';). all i had to do was to type in the index.php back like ($config['index_page'] = 'index.php';). – immanuelx Jun 07 '13 at 10:00
0
Check the uri_protocol in the config file that should be AUTO.

Config/config.php ===> $config['uri_protocol']  = 'AUTO';
vinod
  • 2,850
  • 1
  • 18
  • 23
0

create a .htaccess file inside your root directory and write the below code there.

DirectoryIndex index.php

Options -Indexes

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Aditya Tomar
  • 841
  • 1
  • 13
  • 20
-1

I had that problem but It coused by moving project from window to linux, I solve this by writing the controller as it is. example http://localhost/AppController/blog instead of using http://localhost/appcontroller/blog thanks!

  • Answers added to this page must only answer the asker's specific question, not merely experience a similar problem (typo). – mickmackusa Aug 09 '22 at 08:22
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 12 '22 at 13:10
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/32442265) – Richy B. Aug 13 '22 at 21:02