Search code examples
phpfatal-errorrequire-once

PHP fatal error in require_once() can n


I have a php file in other directory and i wanna use some data of it,but when i require_once() the file i see this error:

Fatal error: require_once(): Failed opening required '/Controller/UserController' (include_path='.;C:\php\pear') in E:\wamp\www\newmvc\index.php on line 20

newmvc is my root and i'm sure there is no misspelling and i have the file.

$Controller="user";
$param=array();
$className=ucfirst($Controller)."Controller";
$controllerfilepath="/Controller/".$className;
require_once "$controllerfilepath";

Solution

  • I suppose you forgot to add an extension .php for class filename:

    $controllerfilepath="/Controller/" . $className . ".php";