Undefined Method find()

Hi everyone!

I have a project from my school, and i have to use yii

Im new in yii and i try to insert field into database

but i’ve got an error like this

And this is my Biodata Model :




<?php


namespace common\models\pendaftaran;


use Yii;


/**

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

 *

 * @property integer $no_peserta

 * @property string $nisn

 * @property string $asal_sekolah

 * @property string $nama_lengkap

 * @property string $jenis_kelamin

 * @property string $tempat_lahir

 * @property string $tanggal_lahir

 * @property string $agama

 * @property string $kebutuhan_khusus

 * @property string $alamat

 * @property string $rt

 * @property string $rw

 * @property string $kelurahan

 * @property string $kecamatan

 * @property string $kabupaten

 * @property string $kode_pos

 * @property string $nohp

 * @property string $kewarganegaraan

 * @property string $tinggal_bersama

 *

 * @property Siswa $noPeserta

 */

class Biodata extends \yii\db\ActiveRecord

{

    /**

     * @inheritdoc

     */

    public static function tableName()

    {

        return 'biodata';

    }




    /**

     * @return \yii\db\ActiveQuery

     */

    public function getNoPeserta()

    {

        return $this->hasOne(Siswa::className(), ['id' => 'no_peserta']);

    }

}




And this is my BiodataForm Model:




<?php


namespace frontend\models;


use Yii;

use yii\base\Model;


use common\models\pendaftaran\Biodata;




class BiodataForm extends Model

{

    public $nisn;

    public $asal_sekolah;

    public $nama_lengkap;

    public $jenis_kelamin;

    public $tempat_lahir;

    public $tanggal_lahir;

    public $agama;

    public $kebutuhan_khusus;

    public $alamat;

    public $rt;

    public $rw;

    public $kelurahan;

    public $kecamatan;

    public $kabupaten;

    public $kode_pos;

    public $nohp;

    public $kewarganegaraan;

    public $tinggal_bersama;


    public static function tableName()

    {

        return 'biodata';

    }


    public function rules()

    {

        return [

            [['nama_lengkap', 'jenis_kelamin', 'tempat_lahir', 'tanggal_lahir', 'agama', 'kebutuhan_khusus', 'alamat', 'rt', 'rw', 'kelurahan', 'kecamatan', 'kabupaten', 'kode_pos', 'nohp', 'kewarganegaraan'], 'required'],            

            [['tinggal_bersama'], 'string'],

            [['nisn'], 'string', 'max' => 11],

            [['asal_sekolah', 'nama_lengkap', 'jenis_kelamin', 'tempat_lahir', 'tanggal_lahir', 'agama', 'kebutuhan_khusus', 'alamat', 'rt', 'rw', 'kelurahan', 'kecamatan', 'kabupaten', 'kode_pos', 'nohp', 'kewarganegaraan'], 'string', 'max' => 255],

            [['nohp'], 'unique'],            

            [['nisn'], 'unique'],            

        ];

    }


    /**

     * @inheritdoc

     */

    public function attributeLabels()

    {

        return [            

            'nisn' => 'Nomor Induk Siswa Nasional',

            'asal_sekolah' => 'Asal Sekolah',

            'nama_lengkap' => 'Nama Lengkap',

            'jenis_kelamin' => 'Jenis Kelamin',

            'tempat_lahir' => 'Tempat Lahir',

            'tanggal_lahir' => 'Tanggal Lahir',

            'agama' => 'Agama',

            'kebutuhan_khusus' => 'Kebutuhan Khusus',

            'alamat' => 'Alamat',

            'rt' => 'Rt',

            'rw' => 'Rw',

            'kelurahan' => 'Kelurahan',

            'kecamatan' => 'Kecamatan',

            'kabupaten' => 'Kabupaten',

            'kode_pos' => 'Kode Pos',

            'nohp' => 'Nohp',

            'kewarganegaraan' => 'Kewarganegaraan',

            'tinggal_bersama' => 'Tinggal Bersama',

        ];

    }

}



And this is the controller :




public function actionBiodata()

    {

        $forms = new BiodataForm();

        if ($forms->load(Yii::$app->request->post()) && $forms->validate()) {

            $bioModel = new Biodata();

            $dataBio = \Yii::$app->request->post('BiodataForm', []);

            // Form Biodata

            $bioModel->no_peserta = $userId;

            $bioModel->nisn = isset($dataRegis['nisn']) ? $dataRegis['nisn'] : null;

            $bioModel->asal_sekolah = isset($dataRegis['asal_sekolah']) ? $dataRegis['asal_sekolah'] : null;

            $bioModel->nama_lengkap = isset($dataRegis['nama_lengkap']) ? $dataRegis['nama_lengkap'] : null;

            $bioModel->jenis_kelamin = isset($dataRegis['jenis_kelamin']) ? $dataRegis['jenis_kelamin'] : null;

            $bioModel->tempat_lahir = isset($dataRegis['tempat_lahir']) ? $dataRegis['tempat_lahir'] : null;

            $bioModel->tanggal_lahir = isset($dataRegis['tanggal_lahir']) ? $dataRegis['tanggal_lahir'] : null;

            $bioModel->agama = isset($dataRegis['agama']) ? $dataRegis['agama'] : null;

            $bioModel->kebutuhan_khusus = isset($dataRegis['kebutuhan_khusus']) ? $dataRegis['kebutuhan_khusus'] : null;

            $bioModel->alamat = isset($dataRegis['alamat']) ? $dataRegis['alamat'] : null;

            $bioModel->rt = isset($dataRegis['rt']) ? $dataRegis['rt'] : null;

            $bioModel->rw = isset($dataRegis['rw']) ? $dataRegis['rw'] : null;

            $bioModel->kelurahan = isset($dataRegis['kelurahan']) ? $dataRegis['kelurahan'] : null;

            $bioModel->kecamatan = isset($dataRegis['kecamatan']) ? $dataRegis['kecamatan'] : null;

            $bioModel->kabupaten = isset($dataRegis['kabupaten']) ? $dataRegis['kabupaten'] : null;

            $bioModel->kode_pos = isset($dataRegis['kode_pos']) ? $dataRegis['kode_pos'] : null;

            $bioModel->nohp = isset($dataRegis['nohp']) ? $dataRegis['nohp'] : null;

            $bioModel->kewarganegaraan = isset($dataRegis['kewarganegaraan']) ? $dataRegis['kewarganegaraan'] : null;

            $bioModel->tinggal_bersama = isset($dataRegis['tinggal_bersama']) ? $dataRegis['tinggal_bersama'] : null;

            $bioModel->save();


            return $this->goHome();

        } else {

            $biodata = new BiodataForm();

            return $this->render('formulir/biodata', [

                'biodata' => $biodata,

            ]);            

        }


    }



Hi,

I think you are wrongly passing the model instance to the view file. Try changing the model into Biodata() will solve the problem.





public function actionBiodata() {

    $forms = new BiodataForm();

    if ($forms->load(Yii::$app->request->post()) && $forms->validate()) {

        $bioModel = new Biodata();

        $dataBio = \Yii::$app->request->post('BiodataForm', []);

        // Form Biodata

        $bioModel->no_peserta = $userId;

        $bioModel->nisn = isset($dataRegis['nisn']) ? $dataRegis['nisn'] : null;

        $bioModel->asal_sekolah = isset($dataRegis['asal_sekolah']) ? $dataRegis['asal_sekolah'] : null;

        $bioModel->nama_lengkap = isset($dataRegis['nama_lengkap']) ? $dataRegis['nama_lengkap'] : null;

        $bioModel->jenis_kelamin = isset($dataRegis['jenis_kelamin']) ? $dataRegis['jenis_kelamin'] : null;

        $bioModel->tempat_lahir = isset($dataRegis['tempat_lahir']) ? $dataRegis['tempat_lahir'] : null;

        $bioModel->tanggal_lahir = isset($dataRegis['tanggal_lahir']) ? $dataRegis['tanggal_lahir'] : null;

        $bioModel->agama = isset($dataRegis['agama']) ? $dataRegis['agama'] : null;

        $bioModel->kebutuhan_khusus = isset($dataRegis['kebutuhan_khusus']) ? $dataRegis['kebutuhan_khusus'] : null;

        $bioModel->alamat = isset($dataRegis['alamat']) ? $dataRegis['alamat'] : null;

        $bioModel->rt = isset($dataRegis['rt']) ? $dataRegis['rt'] : null;

        $bioModel->rw = isset($dataRegis['rw']) ? $dataRegis['rw'] : null;

        $bioModel->kelurahan = isset($dataRegis['kelurahan']) ? $dataRegis['kelurahan'] : null;

        $bioModel->kecamatan = isset($dataRegis['kecamatan']) ? $dataRegis['kecamatan'] : null;

        $bioModel->kabupaten = isset($dataRegis['kabupaten']) ? $dataRegis['kabupaten'] : null;

        $bioModel->kode_pos = isset($dataRegis['kode_pos']) ? $dataRegis['kode_pos'] : null;

        $bioModel->nohp = isset($dataRegis['nohp']) ? $dataRegis['nohp'] : null;

        $bioModel->kewarganegaraan = isset($dataRegis['kewarganegaraan']) ? $dataRegis['kewarganegaraan'] : null;

        $bioModel->tinggal_bersama = isset($dataRegis['tinggal_bersama']) ? $dataRegis['tinggal_bersama'] : null;

        $bioModel->save();


        return $this->goHome();

    } else {

        $biodata = new Biodata(); //Change to your model that associated to the Database Table

        return $this->render('formulir/biodata', [

                    'biodata' => $biodata,

        ]);

    }

}



Even it is not working please share the exact snippet used in the view file.

Thanks for the help, thats work ;D