2014-03-27 42 views
0

我想在一個默認模型中加載另一個模型。我在我的數據庫中有一個配置文件表。但得到錯誤。在默認模型中加載另一個模型

用戶模式

App::uses('AuthComponent', 'Controller/Component'); 
    class User extends AppModel { 

      public function getProfileData(){ 
       $this->loadModel('Profile'); 
       $profileData = $this->Profile->findById('8'); 
       print_r($profileData); 
      } 
    } 

錯誤:

Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'loadModel' at line 1 

SQL Query: loadModel 

回答

2

loadmodel作品控制器。

要使用在當前的新模式,嘗試:

App::uses('Profile', 'Model'); 
$Profile = new Profile(); 
$profileData = $Profile->findById('8'); 
+0

ohk我已經嘗試過,但現在錯誤:未找到類「配置文件」。 App :: uses('AuthComponent','Controller/Component'); App :: uses('Profile','Model'); class User extends AppModel public Profile getProfileData(){ \t \t $ Profile = new Profile(); \t \t $ profileData = $ Profile-> findById('8'); \t \t print_r($ profileData); \t} } –

+0

配置文件模型在其他地方工作正常嗎?你能粘貼它的第一行嗎? – cornelb

+0

我沒有嘗試過任何地方......這是我第一次嘗試使用個人資料模型。 –

0

或許輪廓模型已經與用戶模型相關聯。 如果是這樣的話,您可以使用訪問:

$this->User->Profile->findById(8); 

無需加載任何東西。