extensions are packages specifically designed to be used in yii applications. you can share your own code as an extension or use third-party extensions to add features to your application.
using extensions
most extensions are distributed as composer packages. composer installs packages from packagist – the repository for composer packages.
to install a third-party extension, you should −
add the extension to a composer.json file.
run composer install.
adding date and time widget
let us add a neat datetime widget to our project.
step 1 − modify the composer.json file of the basic application template this way.
{
   "name": "yiisoft/yii2-app-basic",
   "description": "yii 2 basic project template",
   "keywords": ["yii2", "framework", "basic", "project template"],
   "homepage": "http://www.yiiframework.com/",
   "type": "project",
   "license": "bsd-3-clause",
   "support": {
      "issues": "https://github.com/yiisoft/yii2/issues?state=open",
      "forum": "http://www.yiiframework.com/forum/",
      "wiki": "http://www.yiiframework.com/wiki/",
      "irc": "irc://irc.freenode.net/yii",
      "source": "https://github.com/yiisoft/yii2"
   },
   "minimum-stability": "stable",
   "require": {
      "php": ">=5.4.0",
      "yiisoft/yii2": ">=2.0.5",
      "yiisoft/yii2-bootstrap": "*",
      "yiisoft/yii2-swiftmailer": "*",
      "kartik-v/yii2-widget-datetimepicker": "*"
   },
   "require-dev": {
      "yiisoft/yii2-codeception": "*",
      "yiisoft/yii2-debug": "*",
      "yiisoft/yii2-gii": "*",
      "yiisoft/yii2-faker": "*"
   },
   "config": {
      "process-timeout": 1800
   },
   "scripts": {
      "post-create-project-cmd": [
         "yii\\composer\\installer::postcreateproject"
      ]
   },
   "extra": {
      "yii\\composer\\installer::postcreateproject": {
         "setpermission": [
            {
               "runtime": "0777",
               "web/assets": "0777",
               "yii": "0755"
            }
         ],
         "generatecookievalidationkey": [
            "config/web.php"
         ]
      },
      "asset-installer-paths": {
         "npm-asset-library": "vendor/npm",
         "bower-asset-library": "vendor/bower"
      }
   }
}
we have added the dependency "kartik-v/yii2-widget-datetimepicker": "*" to the required section.
step 2 − now, inside the project root, run the composer update to update all the dependencies.
we have just installed the extension. you will find it inside the vendor/kartik-v/yii2widget-datetimepicker folder.
step 3 − to display the newly installed widget in the page, modify the about view of the actionabout method of the sitecontroller.
<?php
   /* @var $this yii\web\view */
   use kartik\datetime\datetimepicker;
   use yii\helpers\html;
   $this->title = 'about';
   $this->params['breadcrumbs'][] = $this->title;
   $this->registermetatag(['name' => 'keywords', 'content' => 'yii, developing, views,
      meta, tags']);
   $this->registermetatag(['name' => 'description',
      'content' => 'this is the description of this page!'], 'description');
?>
<div class="site-about">
   <h1><?= html::encode($this->title) ?></h1>
   <p>
      this is the about page. you may modify the following file to customize its content:
   </p>
   <?php
      echo datetimepicker::widget([
         'name' => 'dp_1',
         'type' => datetimepicker::type_input,
         'value' => '23-feb-1982 10:10',
         'pluginoptions' => [
            'autoclose'=>true,
            'format' => 'dd-m-yyyy hh:ii'
         ]
      ]);
   ?>
</div>
step 4 − now, run the built-in php server from the project root via the php -s localhost:8080t web command.
step 5 − go to http://localhost:8080/index.php?r=site/about. you will see a neat datetime picker as shown in the following screenshot.