2016-11-04 98 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(); 
相關問題