I am building a tiny PHP MVC framework and here is my folder structure
/app
/controllers
/models
/views
/templates
/config
/config.php
/core
/Controller.php
/Router.php
/init.php
/index.php
Inside the index.php which is the front controller I have this code to require the init.php from /app/core/init.php
index.php
<?php
require_once 'app/core/init.php'
$Router = new Router();
$Controller = new Controller();
?>
app/core/init.php
<?php
require_once 'Controller.php';
require_once 'Router.php';
?>
The init.php requires every base controller and classe in /core directory including Controller.php and Router.php and here the index.php also instantiates the classes
Every thing works fine at this point as I tested this by creating the constructor in both Controller.php and Router.php so the code in these two files will be like this
app/core/Controller.php
<?php
class Controller {
public function __construct() {
echo 'OK!';
}
}
?>
app/core/Router.php
<?php
class Router {
public function __construct() {
echo 'OK!';
}
}
?>
inside the index.php it echoes OK! as the classes are instantiates correctly but the problem is that when I want to include the config.php which is located in /app/config/config.php from the Controller.php located in /app/core/Controller.php with this code
<?php
class Controller {
public function __construct() {
require_once '../config/config.php';
}
}
?>
Whenever I do this it returns this error
Controller::include(../config/config.php) [controller.include]: failed to open stream: No such file or directory in C:\AppServ\www\myapp\app\core\Controller.php on line 6
and
Controller::include() [function.include]: Failed opening '../config/config.php' for inclusion (include_path='.;C:\php5\pear') in C:\AppServ\www\myapp\app\core\Controller.php on line 6
I think I used the correct location, I am working from /app/core/Controller.php and want to require /app/config/config.php. I go back one directory using ../
Then why can't I require the file?
configin the controller? your method is not right to have a working mvc - absfrm