Yii1/Yii2: How to organize code in web application?

971 views Asked by At

When should I use applications, when modules or when should I just use controllers? I'm not sure how to divide my code into these components and I don't know when to use what. Can anyone provide some strategies or best practices? Or which practices could be regarded as coding horror?

I assume that extensions are intended to be published or to get shared. So these type of items are not relevant to this question.

I know: it depends. But there might be some advises that do not depend that much on the application itself and can be given in general. Or there are advises like: if you application is kind of this then do that.

What would you think about when RBAC comes into play, RESTful APIs or AJAX-related stuff? Or other things.

1

There are 1 answers

0
marc-medley On

The Yii2 Definitive Guide, "Application Structure" section provides application organization information:
http://www.yiiframework.com/doc-2.0/guide-structure-overview.html

Entry Scripts, Controllers, Models, Views, Modules, Filters, Widgets, Assets and Extensions are covered. "Best Practices" can also be found in several of the "Application Structure" subsections.

RBAC is covered in the Yii2 Guide security section. RESTful APIs has it's own Yii2 Guide section. Asynchronous JS could be placed in an Assets Bundle or registered from View with registerJs() or registerJsFile().
http://www.yiiframework.com/doc-2.0/guide-README.html

RBAC, RESTful APIs and Ajax generally fit within the Yii2 "Application Structure" organization.