Deux132
Deux132

Reputation: 3

Returns 404 even if MVC files are setup properly in Codeigniter

My code igniter project is returning 404 whenever I use method that I created in controllers. I have it running on Mac OS Mojave on Apache2. There might be configuration or setting that I missed.

The codeigniter page works fine when opening http://localhost/myproject where I see the welcome page. I have a 404 problem when I start using the new controller class. To make it simple, I created below "Pages.php" controller file inside application/controllers folder:

<?php
class Pages extends CI_Controller {

        public function view()
        {
        echo "running the view method";

        }
}

I expected the page to display "running the view method" but the result is a 404 page at http://localhost/myproject/view or http://localhost/myproject/index.php/view.

Upvotes: 0

Views: 20

Answers (1)

Deux132
Deux132

Reputation: 3

it works by adding below in route.php

$route['(:any)'] = 'pages/$1';

Upvotes: 0

Related Questions