My own extension

Hi guys I want to create my own extension… I have basic app with models, controller, views and one table in DB… I already know how create simple extension (similarly like gii extension generator) but, How can I use my app in it ? What I must not forget ? And simply , how start?

I already have this



    "name": "tomasillo/yii2-currencies",

    "description": "Showing currencies and calculating form euro to another currency",

    "type": "yii2-extension",

    "minimum-stability": "dev",

    "keywords": ["yii2","extension"],

    "authors": [


            "name": "",

            "email": ""



    "require": {

        "yiisoft/yii2": "*",

        "2amigos/yii2-date-picker-widget": "~1.0"


    "autoload": {

        "psr-4": {

            "tomasillo\\currency\\": ""






namespace tomasillo\currency;

Class Module extends \yii\base\Module


    public static function run()


        echo 'start';



?> …

From basic yii app, my page is using model, modelsearch, cotroller, views

And of course DB, but this isn’t important in this moment

So, what to do now ? I’m beginner whit yii but it’s perfect framework so, I want to learn more

Thanks for any help :)

Full-blown application is not an extension. Extension is meant to be reused with any application which is not your case, it seems. If you want to start from this state for each new project, that’s application template. See how basic one made and do alike. Also check

maybe I don’t understand what extension is. Or problem is my English :D

I created a page like on extension.jpg , and i want to only this part of my page like extension

Well, that sounds like a module to me. Check how Gii and Debug are made, read

well, I saw debug and gii. now questions

What for are components and why they are inside yii2-gii ?

If I’ll use in my extension/module my own model, controller and views, how can I reneder my page?. I still have problem with that. I read to many forums and now i’m really confused what I have to do… I’m doing it just for learning but I want to finish this extension, or module… or installable composer package.

Simply, my site works, I want to this page like module or …

I don’t even know what to ask for

If you can’t even sit down and read documentation, there is no way in Hell that you can create your own Yii extension.

If the 1000s of already existing Yii extensions, the excellent Yii guide and the API docs and the well-written source code is of no use to you, what do you want us to do?

You are making the classic newbie mistake of wanting to fly before you can walk.

Slow down.

Write down a list of stuff that you want to know/learn - like ‘components’, ‘models’, ‘views’, ‘controllers’ - and answer your own questions by a combination of reading the docs and writing a lot of code.

No one expects anyone to manage to jump straight into Yii extension writing - that is generally something that you can only do when you have a good handle on Yii programming.

If you like watching a video, then perhaps this will be useful:

But, as I said: you are expected to know the basics.

So, get cracking :)

Overview: http://www.yiiframew…e-overview.html

Application components: http://www.yiiframew…components.html

Controllers: http://www.yiiframew…ontrollers.html

ETC :)

There is even a section about Modules: http://www.yiiframew…re-modules.html

As you can probably guess, Modules are fairly intuitive - provided that you know where/how/why they fit in.

Okay, I’m going to start again. Apparently, there are the things that I overlooked, so I’ll be back sometimes with right issues. thanks :)

okay my module works :) Now I want to create installable composer package with that modue…is ts even possible?

Basically, what you need to create is a Composer package.

Which means that you need to create a composer.json file.

An example:

The name of the module/extension is your-github-username[i]/your-module-name


That is pretty much all you need to do. :)

Take whatever is inside your ‘modules/your-new-module’ directory and turn it into a git repository, add a ‘composer.json’ file, put it on Github and submit a package to Packagist.

If you are just testing, then you can create a local repository and tell composer about it.

The Composer part of making a Yii extension is the hard bit, unfortunately, but it is worth the effort.

For testing a Composer package, I sometimes use method 2 as described in the SO post:

When the package is submitted to Packagist, however, I usually do this instead:

  1. require the package normally.

  2. composer install

  3. go to ‘vendor’ directory and rename the newly installed package directory.

  4. create a soft link to my local package directory (ln -s package /dir/where/package/is)

  5. composer dump-autoload

Every time I change code in my extension, I run ‘composer dump-autoload’ so that it picks up the changes.

When finished developing, I delete the soft link, rename the directory back and run ‘composer update package-name’

(or simply delete the dir and run composer install)

This is a wiki article that covers a way of making a Yii Composer package/extension:

Haven’t tried it myself, but it looks OK. ;)

Thanks man, I completed the extension and it is finally working :) good advices thanks