R
R
ragnarek2015-03-10 11:58:47
Yii
ragnarek, 2015-03-10 11:58:47

How to create yii2 modules correctly and for further posting on github?

Created a module, but ran into a number of problems.
Since when creating it, you need to check its functionality, I created it in a working project and the module was in the modules folder. When it came to uploading it to github, dances began with the search for all used namespaces and their renaming in accordance with the namespace of the module, as an independent unit.
Of course, you can create a module right away in the vendor folder, for example, while immediately spelling the namespace correctly, but again, you will have to edit the composer files so that this module is loaded correctly.
Actually the question is in the title. I do not consider both options convenient, I think that everything should be somehow simpler.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sanex3339, 2015-03-10
@ragnarek

If I understand you correctly, then here is the answer:
Regarding neyspaces, there are 2 options. If you install the module through composer, then write in composer.json

"autoload": {
        "psr-4": { 
            ragnarek\\amazingmodule\\": "" 
        }
    },

Those. this is an alias to the folder with the module, which is located in the folder with your vendor name.
After installation by composer, the whole thing will be written to extensions.php.
Accordingly, namespaces should be of the form everywhere.
If not through composer, then you must immediately register aliases in extensions.php, see examples of other aliases in this file.
Thus, module classes can always be accessed through namespaces
use ragnarek\amazingmodule;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question