Steps to Create component:
Create a folder named components in your project root folder
Create your component inside components folder e.g.: MyComponent.php
namespace app\components;
use Yii;
use yii\base\Component;
use yii\base\InvalidConfigException;
class MyComponent ...
Create function in MyComponent.php
namespace app\components;
use Yii;
use yii\base\Component;
use yii\base\InvalidConfigException;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use app\models\User;
class MyComponent extends Component
...