I am trying to work with namespaces in Fat Free. Everything works fine, but when i ad the namespace, i get this:
Internal Server Error
Fatal error: Class 'Gadgets\iPad' not found
here is my code:
index.php
$f3=require('lib/base.php');
$f3->set('AUTOLOAD','ui/');
$f3->route('GET /', function(){
$obj=new Gadgets\iPad;
echo $obj->hallo('cat');
});
$f3->run();
ui/iPad.php
namespace Gadgets;
class iPad {
function hallo($word){ echo $word;}}
Thank you
Your class file should appear in the
ui\Gadgets
folder (full path:ui\Gadgets\iPad.php
) in order for F3 to find and autoload it. See this answer for more details on F3's autoloader behaviour.To answer your comment "i thought i have to use a namespace so i do not have to make a Gadgets folder", here are two points to keep in mind:
require
orinclude
calls.Both functionalities (namespaces/autoloader) are optional. Use them if you understand and need them.