phpdev
phpdev

Reputation: 511

How to call function of one model in another model in yii 1

I have following code in my StudentsForm model:

public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'sname' => 'Name',
            'fill' => ' Date',
        );
    }

and in my TeacherForm in my model:

 public function attributeLabels()
        {
            return array(
                'id' => 'ID',
                'tname' => ' Teacher Name',
                'fill' => ' Date',
            );
        } 

How can I call attributeLabels() of StudentsForm in TeachersForm. Both models are located in one model

Upvotes: 1

Views: 1120

Answers (2)

satyawan
satyawan

Reputation: 507

you can try this by 2 methods.

  1. by yii method
  2. by using oop

First method.

$studentLable = StudentsForm::model()->attributeLabels();

Second method.

$studentModel = new StudentsForm;

$studentLable = $studentModel->attributeLabels();

Upvotes: 1

Passionate Coder
Passionate Coder

Reputation: 7294

Simply use this

$lables = StudentsForm::model()->attributeLabels();

$lables will be an array

$lables = array(
            'id' => 'ID',
            'sname' => 'Name',
            'fill' => ' Date',
        );

Upvotes: 1

Related Questions