PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, June 26, 2022

[FIXED] How to Extend Yii2-user dektrium profile model to be able to adding more fields

 June 26, 2022     yii2, yii2-basic-app, yii2-user     No comments   

Issue

I need to override the default Profile model. I have managed to add the fields i need but there is something i am missing since. On insert and update these fields are not getting update to the database.

I have created the necessary migrations so i have these fields in the database already

What am i missing> see below my app/models/Profile.php

<?php

namespace app\models;

/**
 * Description Profile
 *
 * This form @overrides dektrium\user\models\Profile
 */
use dektrium\user\models\Profile as BaseProfile;
use yii\web\UploadedFile;
use Yii;
use dektrium\user\models\User;

class Profile extends BaseProfile {

    /**
     * public variables to be added to the model
     */
    public $profile_pic;
    public $expertise_id;
    public $country_id;

    public function rules() {
        $rules = parent::rules();

        $rules['profile_pic'] = ['profile_pic', 'file'];
        $rules['expertise_id'] = ['expertise_id', 'integer'];
        $rules['country_id'] = ['country_id', 'integer'];



        return $rules;
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        $labels = parent::attributeLabels();
        $labels['profile_pic'] = \Yii::t('user', 'Profile Picture');
        $labels['bio'] = \Yii::t('user', 'Biography');
        $labels['expertise_id'] = \Yii::t('user', 'Expertise');
        $labels['country_id'] = \Yii::t('user', 'Country');
        return $labels;
    }




}

Solution

First thing, remove this lines:

public $profile_pic;
public $expertise_id;
public $country_id;

If you already added those fields in the table, you dont need to declare them. As you can see, none of the others properties are being declared either. This is already being done by extending the model from ActiveRecord and declaring the tableName



Answered By - Clyff
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing