2012-08-01 74 views
1

我有兩種模式:Absence, Students;Cakephp 2.0上的關係

缺席取的名字,並從學生缺席數,現在我想鏈接模型在一起,但我一直在努力弄清楚如何將這些關係的映射,

我沒有組表中,原因之前效果很好,但現在蛋糕php說錯誤沒有鏈接模型。,我用這個行之前,工作正常!

$this->loadModel("Student"); 
    $siswas=$this->Student->find('all'); 
    $this->set('students', $siswas); 

,但現在我已經檢測到錯誤,命名爲內部服務器500,我不知道我有什麼做的, 之前我的應用程序是好的,但現在是什麼問題發生,現在我需要一起鏈接模型,我需要它幫助..

任何幫助將感激..

編輯:

「我的問題已經解決了,這個問題是因爲數據庫是不是活像王好感謝您的答案」

+0

你檢查PHP錯誤日誌什麼導致500錯誤? – Dunhamzzz 2012-08-01 10:17:22

+0

php錯誤日誌說 '2012-08-01 15:11:45警告:Warning(2):explode()期望參數2是字符串,數組在[/ home/magang/public_html/smkn1pst/lib/Cake /View/Helper/FormHelper.php,line 2236] Trace: explode - [internal],line? () - CORE/Cake/View/Helper/FormHelper.php,line 658 FormHelper :: input() - CORE/Cake/View/Helper/FormHelper.php,line 2236 FormHelper :: error ) - CORE/Cake/View/Helper/FormHelper.php,line 1100' – anonymousyoung 2012-08-01 10:27:29

+0

and'include-APP/View/Layouts/default.ctp,line 431 View :: _ render() - CORE/Cake/View/View。 php,line 598 View :: renderLayout() - CORE/Cake/View/View.php,第414行 View :: render() - CORE/Cake/View/View.php,第376行 Controller :: render( ) - CORE/Cake/Controller/Controller.php,第898行 ExceptionRenderer :: _ outputMessage() - CORE/Cake/Error/ExceptionRenderer.php,第267行 ExceptionRenderer :: error500() - CORE/Cake/Error/ExceptionRenderer。 PHP,行234 ExceptionRenderer :: render() - CORE/Cake/Error/ExceptionRenderer.php,第170行# – anonymousyoung 2012-08-01 10:30:43

回答

1

表的結構將是:

Students Table 
id student_name other fields 

absents table 
id student_id other fields 

學生模型赫志

$hasMany = array('Absent'); 

缺席型號赫志

$belongsTo = array('Student'); 
+0

我做得很好,你的下面的方法 我用這個我的缺席模型'公共$ useTable =「缺席」; public $ name ='缺席'; \t \t public $ belongsTo = array('Student');' 我將這個用於我的學生模型'public $ useTable =「students」; public $ name ='Student'; \t \t公共$的hasMany =陣列(「缺席」);' 和我禁止我上面的代碼(我的問題),但仍無法工作 我需要你就像幫助這個錯誤是竊聽我的日子兄弟。 – anonymousyoung 2012-08-02 02:27:18