📜 ⬆️ ⬇️

Automatic code generation in Yii

Hi% username%! A few years ago, I became acquainted with the wonderful framework Yii, and since I only have the opportunity to run a project on it, I fight for it.

One of the coolest features I really love is the Gii tool, which since version 1.1.2 has been included with the framework. Now I want to talk to third-party modules based on it.

Gii Out Of The Box generates a fairly functional code, often when you need to create a small feature, you have to change very little. But what if we need more features? For example, add support for multiple languages, or change the style of the generated code?
There are 2 ways to expand: Modify existing templates and create your own generators (or use ready-made ones, respectively). On the basis of these features, quite interesting products were created for comfortable work with auto code generation.

Giix


Extension page
Perhaps my favorite generator. Generates for models a base class with code and a separately empty model class with inheritance from the base class. Thus, when changing the base, you can re-generate without mashing your code.
')
It also generates a view considering the links, which very often saves a ton of time.

Main features



Practice has shown that this generator, when properly designed database generates a lot of the desired code.

Manymanyajaxcrudadmin


Extension page
Pretty cool stuff. Provides a template for generating code using ajax in the frontend for models with MANY_MANY bundles. Convenient when you need to create an entity for example “product” or “category”.

For example, for the product we use the usual CListView or CGridView and for categories we can use nestedset, edited using the jstree plugin.

The whole thing is edited in modal dialogs, with the ability to attach files.
Based on Giix.

Conclusion


There are much more models and pattern sets for generating, I described only those that I had to use and which I really like.
The idea of ​​a fork for Giix does not leave me, there are really good ideas about this extension, for example: add customization of field types before generation, customization of rules, filters, perhaps it should be issued as a new module for yii2. Time will tell.

This is my first article, before that I could only troll. For trolling and insulting other users, I apologize earlier. Tips and criticism on writing an article, please write in a personal, with errors to the same (my Russian is bad, I know, I'm working on it).

References:
manymanyajaxcrudadmin
giix
Automatic code generation in Yii

Source: https://habr.com/ru/post/191436/


All Articles