Reputation: 1591
So i did try namespace without slim and it was working without any problem but when in slim keeps showing :
500 server error
Composer.json:
{
"require":{
"slim/slim":"2.*",
"slim/extras":"2.*",
"twig/twig":"1.*",
"slim/pdo": "~1.6"
},
"autoload":{
"psr-4":{
"Ultimateboard\\": "src"
}
}
}
MainController.php
namespace Ultimateboard;
class MainController {
function __construct(){
}
public function index(){
echo 'hello main controller index';
}
}
index.php
require_once 'vendor/autoload.php';
require_once 'app/loads/routes.php';
how i have did try to call the methods :
1 Routes.php
$app = new \Slim\Slim(
array(
'view'=> new \Slim\Extras\Views\Twig(),
'debug'=> true
)
);
$app->get('/',Ultimateboard\MainController);
$app->get('/testing',function(){
echo 'testing works';
});
$app->run();
or
Routes.php
$app = new \Slim\Slim(
array(
'view'=> new \Slim\Extras\Views\Twig(),
'debug'=> true
)
);
$app->get('/',function(){
use \Ultimateboard\MainController as MainController;
new MainController()->index();
});
$app->get('/testing',function(){
echo 'testing works';
});
$app->run();
directory structure:
Maybe im missing something or going in conflict with something , did try many answers on different sites but nuthing worked thats why posting it here.
Upvotes: 1
Views: 392
Reputation: 1591
resvoled by changing the namespace to
namespace \Ultimateboard\Controllers;
and routes to :
$app->get('/',function() use ($app){
(new Ultimateboard\Controllers\Maincontroller())->index();
});
Upvotes: 1