Monayem Islam
Monayem Islam

Reputation: 334

How can I fix this "Object not found!" error in CodeIgniter-4?

I have checked the controller name and method name but still it says "The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again."

I have tried this url's given below and got this error:

http://localhost/framework/index.php/helloworld
http://localhost/framework/helloworld/index

File under Controller name is: Helloworld.php

<?php namespace App\Controllers;
use CodeIgniter\Controller;
class Helloworld extends CI_Controller
{
public function index()
{
echo 'Hello World!';
}

enter image description here

Upvotes: 1

Views: 1811

Answers (4)

TimBrownlaw
TimBrownlaw

Reputation: 5507

In the the majority of comments, it was stated that all you had to do was to rename your CI_Controller to plain simple ole Controller ( as per the CI 4 User guide ) and what you declared in your "use".

So you would have

<?php namespace App\Controllers;

use CodeIgniter\Controller; // This is what you are "use"ing

class Helloworld extends Controller {  // And this is where you are "use"ing it
    public function index() {
        echo 'Hello World!';
    }
}

See the difference?

Upvotes: 0

Alok Mali
Alok Mali

Reputation: 2881

Please try after performing below changes -

  • Remove use statement.
  • Extend BaseController as CI_Controller is not available in CI4.
  • Return what you want to show on the screen.

    <?php namespace App\Controllers;
    
     class Helloworld extends BaseController {
       public function index() {
           return 'Hello World!';
       }
     }
    

Upvotes: 0

M B Parvez
M B Parvez

Reputation: 816

Change

class Helloworld extends CI_Controller

to

class Helloworld extends Controller

in CI4 CI_Controller renamed as Controller

Upvotes: 3

Boominathan Elango
Boominathan Elango

Reputation: 1191

If You are trying Codeigniter 4 without using htaccess you should call like

http://localhost/framework/public/helloworld

Or you should run the Codeigniter using this Command

php spark serve 

After that go to browser check http://localhost:8080

You should learn the basics of codeigniter 4 From here How to Use codeigniter 4

Hope this Helps

Upvotes: 1

Related Questions