CodeIgniter升级到了CodeIgniter4后初次体验遇到了很多问题,官方文档也太想让人吐槽了
1、显示Whoops!
解决:在php.ini文件中删除“;extension=intl”前面的“;” 。
2、编写控制器后,在浏览器中显示404
解决:在Routes.php中设置路由(如:$routes->get(‘/index’, ‘Home::index’);)
url:https://x.x.x/index
3、获取URL参数(如:http://x.x.x/Gdcool/view/12)
解决:在Routes.php中设置路由(如:$routes->get(‘/Gdcool/view/(:any)’, ‘Gdcool::view’);)
在控制器中用“$this->request->uri->getSegment(3);”获取到URL中的12
4、提交form表单后显示404错误
解决:需要在路由中指定方法,在Routes.php中设置:
$routes–>post(‘/register’, ‘Auth::register’);
或者:$routes–>match([‘get’, ‘post’], ‘/register’, ‘Auth::register’);
或者:$routes–>add(‘/register’, ‘Auth::register’);