PHP/CodeIgniter4

CodeIgniter 4.2.0 부터는 autoRoute가 비활성화(false)되어 있습니다

6미리 2022. 7. 9. 20:18

https://codeigniter.com/user_guide/incoming/routing.html?highlight=setautoroute#use-defined-routes-only 

 

URI Routing — CodeIgniter 4.2.1 documentation

All of the methods for creating a route (add, get, post, resource etc) can take an array of options that can modify the generated routes, or further restrict them. The $options array is always the last parameter: Assigning Namespace While a default namespa

codeigniter.com

 

그간의 ci는 setAutoRoute 가 활성화 되어 있습니다.

 

/app/Config/Routes.php 에 보면 보통은 24번 라인에 활성화가 되어 있습니다.

이게 4.2.0 부터는 비활성화 되어 있습니다.

이유는 레거시이기 때문이라하는데요.

// The Auto Routing (Legacy) is very dangerous. It is easy to create vulnerable apps
// where controller filters or CSRF protection are bypassed.
// If you don't want to define all routes, please use the Auto Routing (Improved).
// Set `$autoRoutesImproved` to true in `app/Config/Feature.php` and set the following to true.
// $routes->setAutoRoute(true);

기존 자동 라우팅은 위험하기 때문에 비활성화되어 있으니 항상 선언을 해서 사용해 달라는 이야기입니다.

물론 아직까지는 활성화 해놓고 쓸 수 있습니다.

다만 보안에 문제가 생기는 부분이라 향후 사라질 가능성이 높으니 이제는 다 정해서 사용하면 됩니다.

이게 그 동안은 어지간한 프로젝트에서는 다 정해놓고 쓰다가 이번에 토이프로젝트 진행중에 안되다가 찾아보니 변경되었더라고요.

 

참고로 새로운 기능인 autoRoutesImproved 가 있습니다. Feature.php에서 활성화해서 사용해보세요.

 

도움이 되면 좋겠습니다.