0

I have main index.php file where i call other controllers and that is fine.

I call them with call_user_func_array([$object, $this->method], $this->params);

For example i first include controller and then i call it. My controller is called IndexController and this is example how i include it and call it.

IndexController.php

<?php

class IndexController extends Controller {

    function __construct()
    {
        print 'welcome to oxbir'."<BR>";
    }

    function index()
    {
        $this->view('panel/user');
    }
}

Controller.php

<?php

class Controller
{
    function __construct()
    {

    }

    function view($view)
    {
        include('views/'.$view.'.php');
    }
}

but I see this error...

Fatal error: Class 'Controller' not found in C:\xampp\htdocs\site\php\controllers\IndexController.php on line 3

4
  • You have to include or require the files where the required class is defined. So you indexController.php needs require("Controller.php"); at the begin. Commented Jul 5, 2019 at 21:29
  • I changed it, but I did not solve my problem Commented Jul 5, 2019 at 21:35
  • So please edit your question to reflect the changes you made. Commented Jul 5, 2019 at 21:38
  • I changed my post, you can see now. Commented Jul 5, 2019 at 21:50

1 Answer 1

1

Change

<?php

class IndexController extends Controller {

To

<?php
require_once('Controller.php');

class IndexController extends Controller {

You need to include the controller file or use some kind of autoload.

Sign up to request clarification or add additional context in comments.

2 Comments

So your Controller.php is not in the same folder?
All you have to do is to include the file. If it is in a different folder, set the relative or absolute path to the file, like './Controller.php', or __DIR__.'/../Controller.php'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.