We are thrilled to inform you that Lancecourse is NOW INIT Academy — this aligns our name with our next goals — Read more.

It seems like you are using an ad blocker. To enhance your experience and support our website, please consider:

  1. Signing in to disable ads on our site.
  2. Sign up if you don't have an account yet.
  3. Or, disable your ad blocker by doing this:
    • Click on the ad blocker icon in your browser's toolbar.
    • Select "Pause on this site" or a similar option for INITAcademy.org.

PHP Frameworking - Routing & Autoloading & Configuration (Part 2)

By Matej 10 years ago
Respond to different URLs & care less about require statements

8 Comments

Sign in to reply

zooboole
zooboole
10 years ago Reply
If you have a php version lower than PHP 5.4 use this:|

private $autoloadable = array();
Auto
Auto
10 years ago Reply
First off, thanks for making this tut. I got an issue though. I am getting a fatal error having to do with the BASEPATH constant:

Notice: Use of undefined constant BASEPATH - assumed \'BASEPATH\' in C:\\xampp\\htdocs\\mvc-PHP2\\bootstrap.php on line 8

Fatal error: Uncaught exception \'Exception\' with message \'View does not exist: BASEPATH/views/hello.php\'

Followed everything exactly, just can\'t get past. Maybe I\'m missing something simple, please enlighten me.
Auto
Auto
10 years ago Reply
I just could not let it go. I kept at it. Something so simple as a constant that just doesn\'t seem to work was racking my mind, I could understand if it was some very complex operations but... Anyhow I stepped back, relaxed and cleared my head by just watching a little tv and throwing in a movie which I skipped through. In any event, that kinda allowed me to look at what was going on from a high level, i.e What is this constant BASEPATH doing anyway ? What\'s it purpose to begin with ? Its just a pointer to the root directory at the end of the day. Why does it need to be a in its own separate file \"config.php\" when \"bootstrap.php\" is at the same directory level ? It doesn\'t. So I did away with requiring \"config.php\" altogether. No need. Just moved defining BASEPATH to \"boostrap.php\"


/*boostrap.php */
define(\'BASEPATH\', dirname(realpath(__FILE__)));
// Samething
define(\'BASEPATH\', __DIR__);

I don\'t know why this caused an error in the first place.
zooboole
zooboole
10 years ago Reply
**Auto default**, The `config.php` becomes very useful when your project becomes bigger. This file could contain other settings your app could need. Now for you bringing it into bootstrap does not cause any issue as far as I am concerned.

But one thing you should also consider is your PHP Version. Can you please tell us the version of PHP you are using? Thanks.
zooboole
zooboole
10 years ago Reply
You can also check out this comment : [http://phpocean.com/tutorials/back-end/php-frameworking-introduction-part-1/9#4](http://phpocean.com/tutorials/back-end/php-frameworking-introduction-part-1/9#4)
Auto
Auto
10 years ago Reply
**Zooboole**, I\'m running PHP 5.6.3 and I did play around with the directory path as per your suggestion but some reason BASEPATH is just not making it to /public/index.php

And I agree with about \"config.php\" and it role down the road but for now I\'m going to go with having BASEPATH in \"bootstrap.php\" so I can move forward with this tutorial. Afterwards I\'ll come back to it.
zooboole
zooboole
10 years ago Reply
Great, I will also give a closer look at it. If anything I will surely let you know.
Auto
Auto
10 years ago Reply
I added the router class, instantiated it in \"bootstrap.php\" and added the routes in separate \"routes.php\" file which is required in \"index.php\" but I\'m still getting a 404 not found! page

404 - /mvc-PHP2/public/about-us was not found!;

after this code is in place:

$router->add(\'/about-us\', function() use ($view) {
$view->display(\'about.php\');

And I did create a test page \"about.php\" in the views folder.