1

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

Monayem Islam
  • 294
  • 3
  • 15
  • 1
    Take a look at https://stackoverflow.com/questions/19183311/codeigniter-removing-index-php-from-url – bestprogrammerintheworld Apr 13 '20 at 09:48
  • Re read what you have in your use statement... Its "use CodeIgniter\Controller" for your extended class... But on careful observation you have incorrectly used CI_Controller which is so CI 3ish. – TimBrownlaw Apr 13 '20 at 15:50

4 Answers4

3

Change

class Helloworld extends CI_Controller

to

class Helloworld extends Controller

in CI4 CI_Controller renamed as Controller

M B Parvez
  • 808
  • 6
  • 16
  • Controller name is corrected but still getting Fatal error: Class 'App\Controllers\Controller' not found in C:\xampp\htdocs\ci\app\Controllers\Helloworld.php on line 3 – Monayem Islam Apr 13 '20 at 16:40
  • @MonayemIslam Please see my answer. You have removed the use statement. You need to understand how this works. – TimBrownlaw Apr 18 '20 at 18:11
1

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

Boominathan Elango
  • 1,156
  • 2
  • 7
  • 20
0

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!';
       }
     }
    
Alok Mali
  • 2,821
  • 2
  • 16
  • 32
  • 1
    It is not quite correct to state that "You Need to run the Spark Server to run the project". It's an option. Have you read the manual :) – TimBrownlaw Apr 13 '20 at 14:34
  • @TimBrownlaw, I agree with you. – Alok Mali Apr 13 '20 at 14:35
  • 1
    @AlokMali Thank You. It works for BaseController and getting a fatal error for Controller. Could you please explain why I am getting a fatal error for Controller? – Monayem Islam Apr 13 '20 at 17:39
  • 1
    Did you have the appropriate use statement for the Controller? Or had you removed it? – TimBrownlaw Apr 13 '20 at 19:09
  • @TimBrownlaw, I don't have use statement as I mentioned above. – Alok Mali Apr 14 '20 at 05:39
  • 1
    Sorry AlokMali, that was directed to @MonayemIslam regarding his question on using Controller instead of BaseController. IN that case the previous use CodeIgniter\Controller is required for that to work. Your answer changed it to use BaseController. – TimBrownlaw Apr 14 '20 at 06:17
  • 1
    @MonayemIslam, I am unable to find, why you are facing this issue. TimBrownlaw, could you please answer it. – Alok Mali Apr 14 '20 at 08:15
0

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?

TimBrownlaw
  • 5,457
  • 3
  • 24
  • 28