I'm currently working with a CodeIgniter3 application, and have built the basis for a standard blog-like system.
The structure is standard CI - User requests a page, page loads controller method, controller method calls any relevant DB functions from its model, and then a view is loaded.
However, I'm looking to also make this view accessible via an API. So, instead of the $data array being filled with information to populate into HTML, I would instead pass it to a different view which would output a JSON result.
I imagine writing two different controllers would be a bad step to take - is there any routing I can do, or any standard practice to allow for the controllers to recognise an api endpoint has been hit (such as the directory 'api' being in the access path), and then load up a different view based on this?