2016-11-04 99 views
1

我已经按照我的StudentsForm型号代码:如何警予调用一个模型的功能在另一个模型1

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

,在我在我的模型TeacherForm:

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

我怎样才能在TeachersForm中调用StudentForm的attributeLabels()。 两款机型都位于一个模型

回答

1

只需使用这个

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

$lables将是一个array

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

您可以通过2种方法试试这个。

  1. 通过YII方法
  2. 通过使用接力

第一方法。

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

第二种方法。

$studentModel = new StudentsForm; 

$studentLable = $studentModel->attributeLabels(); 
相关问题