Best practice for changing YII2 extension

What is the best practice if I want to change some code inside an YII2 extension, if the code is not planned to be merged into the original code?

Example given: I want to remove the demo notice "You may login with neo/neo." in the amnah/yii2-user extension

Do I have to fork on github and use this fork?

What will happen with my fork, if the original code changes?

You can extend the class in your app and change the code in it.

Ok, already thought about this. Which file in which folder is preferred to be used or created for doing this extension?

Can anyone give us a few examples of extending an extension?

Anyone done a tutorial on this?



I succeeded by doing the following for overriding the class function which is responsible for the part i want to change.

If you want to change the output of the login form shown by amnah/yii2-user extension, you have to do the following 3 steps.


[*]Create a new controller file app\controllers\user\DefaultController.php in which you redirect to a custom form template view file by overriding actionLogin() in a custom class overriding the amnah class.


namespace app\controllers\user;

use Yii;

use amnah\yii2\user\controllers\DefaultController as BaseDefaultController;


 * Custom Default controller for User module


class DefaultController extends BaseDefaultController



     * Display login page


    public function actionLogin()


        /** @var \amnah\yii2\user\models\forms\LoginForm $model */

        $model = $this->module->model("LoginForm");

// load post data and login

        $post = Yii::$app->request->post();

        if ($model->load($post) && $model->validate()) {

            $returnUrl = $this->performLogin($model->getUser(), $model->rememberMe);

            return $this->redirect($returnUrl);


        return $this->render('//user/login', compact("model"));



[*]After creating this overriding class and function, you have to add it to the controller map in app/config/web.php

'modules' => [

        'user' => [

            'class' => 'amnah\yii2\user\Module',

            'controllerMap' => [

                'default' => 'app\controllers\user\DefaultController'



[*]Last part is the creation of the view template file in app/views/user/login.php without "You may login with neo/neo." which I want to remove from the original code coming from amnah/yii2-user extension.


use yii\helpers\Html;

use yii\widgets\ActiveForm;


 * @var yii\web\View $this

 * @var yii\widgets\ActiveForm $form

 * @var amnah\yii2\user\models\forms\LoginForm $model


$this->title = Yii::t('user', 'Login');

$this->params['breadcrumbs'][] = $this->title;


<div class="user-default-login">

    <h1><?= Html::encode($this->title) ?></h1>

    <?php $form = ActiveForm::begin([

        'id' => 'login-form',

        'options' => ['class' => 'form-horizontal'],

        'fieldConfig' => [

            'template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-7\">{error}</div>",

            'labelOptions' => ['class' => 'col-lg-2 control-label'],


    ]); ?>

    <?= $form->field($model, 'email') ?>

    <?= $form->field($model, 'password')->passwordInput() ?>

    <?= $form->field($model, 'rememberMe', [

        'template' => "{label}<div class=\"col-lg-offset-2 col-lg-3\">{input}</div>\n<div class=\"col-lg-7\">{error}</div>",

    ])->checkbox() ?>

    <div class="form-group">

        <div class="col-lg-offset-2 col-lg-10">

            <?= Html::submitButton(Yii::t('user', 'Login'), ['class' => 'btn btn-primary']) ?>


            <?= Html::a(Yii::t("user", "Register"), ["/user/register"]) ?> /

            <?= Html::a(Yii::t("user", "Forgot password") . "?", ["/user/forgot"]) ?> /

            <?= Html::a(Yii::t("user", "Resend confirmation email"), ["/user/resend"]) ?>



    <?php ActiveForm::end(); ?>

    <?php if (Yii::$app->get("authClientCollection", false)): ?>

        <div class="col-lg-offset-2 col-lg-10">

            <?= yii\authclient\widgets\AuthChoice::widget([

                'baseAuthUrl' => ['/user/auth/login']

            ]) ?>


    <?php endif; ?>



Ah, great! This helps tie together some of the parts that I have read about, but not quite figured out how to make it work.