core
core copied to clipboard
Flight::path() problem
Hi, i'm trying to make it work on nginx, and just want to understand what im doing wrong
So, here is my nginx cfg where i put try_files from your Installation guide:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/phpmvc.loc;
index index.php index.html index.htm index.nginx-debian.html;
server_name phpmvc.loc;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
Im using composer so there is how my index.php looked like:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include dirname(__FILE__) . '/vendor/autoload.php';
Flight::path(__DIR__ . '/controllers');
include dirname(__FILE__) . '/routes.php';
Flight::start();
And this is my routes.php:
<?php
Flight::route('/', array('MainController', 'index'));
And in this case i have an error all the time in Flight version 1.3
500 Internal Server Error
Invalid callback specified. (0)
#0 /var/www/phpmvc.loc/vendor/mikecao/flight/flight/Engine.php(322): flight\core\Dispatcher::execute()
#1 /var/www/phpmvc.loc/vendor/mikecao/flight/flight/core/Dispatcher.php(196): flight\Engine->_start()
#2 /var/www/phpmvc.loc/vendor/mikecao/flight/flight/core/Dispatcher.php(142): flight\core\Dispatcher::invokeMethod()
#3 /var/www/phpmvc.loc/vendor/mikecao/flight/flight/core/Dispatcher.php(48): flight\core\Dispatcher::execute()
#4 /var/www/phpmvc.loc/vendor/mikecao/flight/flight/Engine.php(65): flight\core\Dispatcher->run()
#5 /var/www/phpmvc.loc/vendor/mikecao/flight/flight/core/Dispatcher.php(196): flight\Engine->__call()
#6 /var/www/phpmvc.loc/vendor/mikecao/flight/flight/Flight.php(77): flight\core\Dispatcher::invokeMethod()
#7 /var/www/phpmvc.loc/index.php(32): Flight::__callStatic()
#8 {main}
And this error in current 2.0.1
Fatal error: Uncaught TypeError: Argument 2 passed to flight\Engine::_route() must be callable, array given, called in /var/www/phpmvc.loc/vendor/mikecao/flight/flight/core/Dispatcher.php on line 227 and defined in /var/www/phpmvc.loc/vendor/mikecao/flight/flight/Engine.php:443 Stack trace: #0 /var/www/phpmvc.loc/vendor/mikecao/flight/flight/core/Dispatcher.php(227): flight\Engine->_route() #1 /var/www/phpmvc.loc/vendor/mikecao/flight/flight/core/Dispatcher.php(162): flight\core\Dispatcher::invokeMethod() #2 /var/www/phpmvc.loc/vendor/mikecao/flight/flight/core/Dispatcher.php(54): flight\core\Dispatcher::execute() #3 /var/www/phpmvc.loc/vendor/mikecao/flight/flight/Engine.php(98): flight\core\Dispatcher->run() #4 /var/www/phpmvc.loc/vendor/mikecao/flight/flight/core/Dispatcher.php(227): flight\Engine->__call() #5 /var/www/phpmvc.loc/vendor/mikecao/flight/flight/Flight.php(97): flight\core\Dispatcher::invokeMethod() #6 /var/www/phpmvc.loc/routes.php(16): Flight::__callStatic() #7 /var/www/phpmvc.loc/index.php(24): include( in /var/www/phpmvc.loc/vendor/mikecao/flight/flight/Engine.php on line 443
And i made it work only when im include my MainController.php directrly in index.php
include dirname(__FILE__) . '/controllers/MainController.php';
and then i added use namespace\MainController.php
in routes.php and made an object
$controller = new MainController();
Flight::route('/', array($controller, 'index'));
After this manipulations its worked, but i want to use Flight::path What i am doing wrong here?
You don't need Flight to autoload classes if you're using composer. Just follow PSR4.
Yes, path just follows the same thing. So you have to namespace your controller to be namespace controllers;
and then you reference your controller with controllers\MainController