Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Best Practice for Splitting Up REST API with Micro Framework?

I'm assuming I should be using the autoloader or something along those lines for this, but I'm being tempted to just make gross PHP and do includes.

What's the best method of splitting up a fairly large API into multiple files so it's easier to work with?

Specifically, I'd like to have my config(DB setup, etc.), models, functions for preparing DB results(controllers? Not sure in Micro), and API routes all separated out with subfolders/subfiles for each.

What's the best practice in Phalcon for doing this?



4.8k

i started with the index.php file performing an initial split. Some requests go to micro, some to a full request for handling an admin interface, and some go to PHP to handle content prepared elsewhere.

At that point you could split the micro based on different areas. If you have one group working on a stock system and another group working on a sales system, you could give the groups separate code for easier management of routing etc.

i started with the index.php file performing an initial split. Some requests go to micro, some to a full request for handling an admin interface, and some go to PHP to handle content prepared elsewhere.

At that point you could split the micro based on different areas. If you have one group working on a stock system and another group working on a sales system, you could give the groups separate code for easier management of routing etc.

So I guess my question is what is the norm for splitting code in Phalcon? Outside a framework I'd normally just have used includes or requires to split it into multiple files, however, it seems like with Dependency Injection and Autoloaders in PhalconPHP there's a better method than that, however I'm uncertain how to apply it in the Micro framework, without views.



3.6k
Accepted
answer

Ah, it appears what I'm going for is a "medium" application, found a good description of how to use controllers with Micro apps here.

Yep, it's perfectly possible to use controllers with micro applications.

Medium approach is the best IMHO, if you can live w/o Dispatcher.



10.2k

Medium approach is the best IMHO, if you can live w/o Dispatcher.

What's IMHO? and what's w/o?