mklemarczyk / yii-prezentacja

Yii 2.0 - prezentacja
GNU General Public License v2.0
0 stars 0 forks source link

Fatal Error, Migracja i smok Wawelski czyli historia o tym, że nie działa.. #25

Closed chomyczek closed 9 years ago

chomyczek commented 9 years ago

udało mi się zmigrować tabele user (tak jak w #10) by udało się zalogować, nastepnie w bazie danych dodałem nową tabelę odwołującą się do user.id i utworzyłem kontroler tej tabeli i teraz nie działa. Wyświetla się następujący komunikat:

PHP Fatal Error – yii\base\ErrorException
Call to undefined method common\models\User::findIdentity()
1. in D:\usbWS\root\aplika\vendor\yiisoft\yii2\web\User.php at line 614
2. yii\base\ErrorHandler::handleFatalError()

ten komunikat wyświetla się na stronie głównej i każdej innej

mklemarczyk commented 9 years ago

21 Opisałem, aby nie usuwać funkcji z modelu User.

Funkcji findIdentity nie ma w modelu User i Yii nie może jej użyć.

chomyczek commented 9 years ago

A jeżeli powiem, że nic z tamtego pliku nie usunąłem?

mklemarczyk commented 9 years ago

Możesz pokazać zawartość pliku common/models/User.php?

chomyczek commented 9 years ago

Powiem tylko, że utworzyłem to na nowym szkielecie Yii, więc nie zdąrzyłem nic zjebać :p

<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "user".
 *
 * @property integer $id
 * @property string $username
 * @property string $auth_key
 * @property string $password_hash
 * @property string $password_reset_token
 * @property string $email
 * @property integer $status
 * @property integer $created_at
 * @property integer $updated_at
 *
 * @property Zamowienie[] $zamowienies
 */
class User extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'user';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['username', 'auth_key', 'password_hash', 'email', 'created_at', 'updated_at'], 'required'],
            [['status', 'created_at', 'updated_at'], 'integer'],
            [['username', 'password_hash', 'password_reset_token', 'email'], 'string', 'max' => 255],
            [['auth_key'], 'string', 'max' => 32]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'username' => Yii::t('app', 'Username'),
            'auth_key' => Yii::t('app', 'Auth Key'),
            'password_hash' => Yii::t('app', 'Password Hash'),
            'password_reset_token' => Yii::t('app', 'Password Reset Token'),
            'email' => Yii::t('app', 'Email'),
            'status' => Yii::t('app', 'Status'),
            'created_at' => Yii::t('app', 'Created At'),
            'updated_at' => Yii::t('app', 'Updated At'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getZamowienies()
    {
        return $this->hasMany(Zamowienie::className(), ['uzytkownik_id' => 'id']);
    }
}
mklemarczyk commented 9 years ago

:anger: I czyli mówisz, że nic nie zmieniałeś, a funkcja zniknęła? :interrobang: Oryginalny plik User.php załączyłeś w issue #21

:information_source: Są tam również adnotacje, co w tym pliku jest ważne i czego nie wolno usuwać.

chomyczek commented 9 years ago

Czy migracja mogła mi zniszczyć system?

mklemarczyk commented 9 years ago

Migracja - nie, ale generowanie modelu User - tak

chomyczek commented 9 years ago

Zacząłem od nowa, bez generowania modelu User, teraz działa :stuck_out_tongue: