Unknown Property when Changing AT Login form

Hi,

I need to change the Advanced Template Login Form in the front end. When logging, user must also select an office from dropdwon. It will help filtering for him only the right database records, later on.

I take the dropdown snipped from another form in the front end, where it is working. When copying it into the Login Form, I get error "Unknown Property – yii\base\UnknownPropertyException".

The code is:


                <?= $form->field($salon, 'location_id')

                               ->dropDownList(

                                   ArrayHelper::map(Location::find()->all(), 'id', 'full_name'),

                                   ['prompt' => 'Choose your office: ']

                               );

                ?>

After I change ‘location_id’ to ‘id’ on the first line above, then the error dissappears and dropdown is visible on the screen. However, when I choose something, the choice (id) is not stored in the model - neither in $salon->id, nor in $salon->location_id .

I played with other models, however always the same behavior - dropdowns work in other forms, but are not working in the Login Form.

Please, help.

Thank you.

The AT Login Form looks like this, after I change it:


<?php

use yii\helpers\Html;

use yii\helpers\ArrayHelper;

use yii\bootstrap\ActiveForm;

use common\models\Location;




/* @var $this yii\web\View */

/* @var $form yii\bootstrap\ActiveForm */

/* @var $model \common\models\LoginForm */


$this->title = 'Login';

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

?>

<div class="site-login">

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


    <p>Choose your office and enter your username and password :: </p>


    <div class="row">

        <div class="col-lg-5">

            <?php $form = ActiveForm::begin(['id' => 'login-form']); ?>

                

                <?= $form->field($salon, 'id')

                               ->dropDownList(

                                   ArrayHelper::map(Location::find()->all(), 'id', 'full_name'),

                                   ['prompt' => 'Choose your office: ']

                               );

                ?>




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

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

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

                <div style="color:#999;margin:1em 0">

                    If you forgot your password you can <?= Html::a('reset it', ['site/request-password-reset']) ?>.

                </div>

                <div class="form-group">

                    <?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>

                </div>

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

        </div>

    </div>

</div>



The SiteController.php login action looks like this:


<?php

namespace frontend\controllers;


use Yii;

use common\models\LoginForm;

use frontend\models\PasswordResetRequestForm;

use frontend\models\ResetPasswordForm;

use frontend\models\SignupForm;

use frontend\models\ContactForm;

use yii\base\InvalidParamException;

use yii\web\BadRequestHttpException;

use yii\web\Controller;

use yii\filters\VerbFilter;

use yii\filters\AccessControl;


use common\models\Location;

use yii\web\Session;


...


   public function actionLogin()

    {

        if (!\Yii::$app->user->isGuest) {

            return $this->goHome();

        }


        $model = new LoginForm();

        


        try {

            $salon = new Location();

        } catch (InvalidParamException $e) {

            throw new BadRequestHttpException($e->getMessage());

        }


        if ($model->load(Yii::$app->request->post()) && $model->login()

                && $salon->load(Yii::$app->request->post()) && $model->validate() ) {


            // Store the Salon into Session variable

            $session = Yii::$app->session;


            if (!$session->isActive) 

            {

                try {

                    $session->open();

                } catch (InvalidParamException $e) {

                    throw new BadRequestHttpException($e->getMessage());

                }

            }


            $session->set('location_id', $salon->id);


            return $this->goBack();

        } else {

            return $this->render('login', [

                'model' => $model,

                'salon' => $salon,

            ]);

        }

    }

And the Location model:


<?php


namespace common\models;


use Yii;


/**

 * This is the model class for table "location".

 *

 * @property integer $id

 * @property string $short_name

 * @property string $full_name

 * @property string $city

 * @property string $address

 * @property string $start_date

 * @property string $end_date

 *

 * @property Appointment[] $appointments

 * @property Invoice[] $invoices

 * @property Payment[] $payments

 * @property PaymentSplitPerLocation[] $paymentSplitPerLocations

 * @property Payment[] $payments0

 * @property Sale[] $sales

 * @property WorkSchedule[] $workSchedules

 */

class Location extends \yii\db\ActiveRecord

{

    /**

     * @inheritdoc

     */

    public static function tableName()

    {

        return 'location';

    }


    /**

     * @inheritdoc

     */

    public function rules()

    {

        return [

            [['short_name', 'full_name', 'start_date'], 'required'],

            [['start_date', 'end_date'], 'safe'],

            [['short_name'], 'string', 'max' => 30],

            [['full_name', 'address'], 'string', 'max' => 75],

            [['city'], 'string', 'max' => 55],

            [['short_name'], 'unique']

        ];

    }


    /**

     * @inheritdoc

     */

    public function attributeLabels()

    {

        return [

            'id' => 'Office',

            'short_name' => 'Office Short Name',

            'full_name' => 'Office Full Name',

            'city' => 'City',

            'address' => 'Address',

            'start_date' => 'Office opened on date',

            'end_date' => 'Office closed on date',

        ];

    }


    /**

     * @return \yii\db\ActiveQuery

     */

    public function getAppointments()

    {

        return $this->hasMany(Appointment::className(), ['location_id' => 'id']);

    }


    /**

     * @return \yii\db\ActiveQuery

     */

    public function getInvoices()

    {

        return $this->hasMany(Invoice::className(), ['location_id' => 'id']);

    }


    /**

     * @return \yii\db\ActiveQuery

     */

    public function getPayments()

    {

        return $this->hasMany(Payment::className(), ['location_id' => 'id']);

    }


    /**

     * @return \yii\db\ActiveQuery

     */

    public function getPaymentSplitPerLocations()

    {

        return $this->hasMany(PaymentSplitPerLocation::className(), ['location_id' => 'id']);

    }


    /**

     * @return \yii\db\ActiveQuery

     */

    public function getPayments0()

    {

        return $this->hasMany(Payment::className(), ['id' => 'payment_id'])->viaTable('payment_split_per_location', ['location_id' => 'id']);

    }


    /**

     * @return \yii\db\ActiveQuery

     */

    public function getSales()

    {

        return $this->hasMany(Sale::className(), ['location_id' => 'id']);

    }


    /**

     * @return \yii\db\ActiveQuery

     */

    public function getWorkSchedules()

    {

        return $this->hasMany(WorkSchedule::className(), ['location_id' => 'id']);

    }

}