Reputation: 103
I have main index.php file where i call other controllers and that is fine.
I call them with call_user_func_array( [ $obj, $method[ 0 ] ], $params );
For example i first include controller and then i call it. My controller is called HomeController and this is example how i include it and call it.
require( 'system/mvc/controller/'. $controller .'.php' );
$obj = new $controller;
call_user_func_array( [ $obj, $method[ 0 ] ], $params );
And that is ok and its working.
So my system/mvc/controller/HomeController.php looks like this:
<?php
class HomeController
{
public function test()
{
echo 'Something!';
}
}
?>
And this is ok. Now i was tried to include main controller.php file that will extends my HomeController. So in my index.php file i included system/lib/php/Controller.php and code now looks like this in index.php
require( 'system/mvc/controller/'. $controller .'.php' );
require( 'system/lib/php/controller.php' );
$obj = new $controller;
call_user_func_array( [ $obj, $method[ 0 ] ], $params );
And in HomeController i used class HomeController extends Controller and i got this error: Fatal error: Class 'Controller' not found in /var/www/html/system/mvc/controller/HomeController.php on line 3
Tried to use namespaces but that didnt work.
Upvotes: 1
Views: 3151
Reputation: 314
Try to change
require( 'system/mvc/controller/'. $controller .'.php' ); require( 'system/lib/php/controller.php' );
to
require( 'system/lib/php/controller.php' ); require( 'system/mvc/controller/'. $controller .'.php' );
Upvotes: 1