2012-04-04 72 views
0

我是MVC和Codeigniter的新手,正在努力爭取上課。找不到類別

我正在笨2.1.0和2.2.1學說

當我的代碼調用提交()函數,我得到Class 'Myclass_model' not found,以及包括該行引用:($u = new Myclass_model();

見編輯注底部,現在越來越Class 'Doctrine_Record' not found在其擴展模型)

在我的控制器是下面的代碼:

public function submit() { 

     if ($this->_submit_validate() === FALSE) { 
      $this->index(); 
      return;  
     } 

     $u = new Myclass_model(); 
     $u->username = $this->input->post('username'); 
     $u->password = $this->input->post('password'); 
     $u->email = $this->input->post('email'); 
     $u->save(); 

     $this->load->view('submit_success'); 
    } 

在我的/應用/模型/文件夾我有myclass.php:

class Myclass extends Doctrine_Record { 

public function setTableDefinition() { 
    $this->hasColumn('username', 'string', 255, array('unique' => 'true')); 
    $this->hasColumn('password', 'string', 255); 
    $this->hasColumn('email', 'string', 255, array('unique' => 'true')); 
} 

public function setUp() { 
    $this->setTableName('testtable1'); 
    $this->actAs('Timestampable'); 
      //$this->hasMutator('password', '_encrypt_password'); 
} 

    protected function _encrypt_password($value) { 
     $salt = '#*[email protected]*%'; 
     $this->_set('password', md5($salt . $value)); 
     //Note: For mutators to work, auto_accessor_override option needs to be enabled. We have already done it, in our plugin file doctrine_pi.php. 

    } 
} 

我懷疑我的問題是延伸Doctrine_Record。我已經安裝了doctrine2,並且在/ application/libraries /中有Doctrine.php和Doctrine文件夾。但我不知道在哪裏檢查,甚至如何檢查並確保Doctrine_Record可用,配置等

誰能幫我解決這一點,並找出問題所在?我的班級有些簡單嗎?我的Doctrine安裝/配置有一些問題?

編輯:我跟着調用類像這樣的建議:

$this->load->model('Myclass_model','u'); 

,我現在越來越Class 'Doctrine_Record' not found在模型擴展Doctrine_Record

回答

0

我懷疑你沒有包括您Myclass.php文件或路徑不正確。如果您在教條擴展中遇到問題,您的錯誤會提及父項。即使如此,請確保您有一個include_once('path/to/doctrine_record');

新類裏面的父文件,您可以將其添加到autoload.php文件或手動像這樣:

public function submit() { 

     if ($this->_submit_validate() === FALSE) { 
      $this->index(); 
      return;  
     } 

     include_once('/path/to/Myclass.php'); 
     $u = new Myclass(); 
     $u->username = $this->input->post('username'); 
     $u->password = $this->input->post('password'); 
     $u->email = $this->input->post('email'); 
     $u->save(); 

     $this->load->view('submit_success'); 
    } 

甚至更​​好,你加載它像一個模型。文件重命名爲myclass_model.php和類名來Myclass_model :)

public function submit() { 

     if ($this->_submit_validate() === FALSE) { 
      $this->index(); 
      return;  
     } 

     $this->load->model('Myclass_model','u'); 
     $this->u->username = $this->input->post('username'); 
     $this->u->password = $this->input->post('password'); 
     $this->u->email = $this->input->post('email'); 
     $this->u->save(); 

     $this->load->view('submit_success'); 
    } 
+0

我固定它加載像模特,現在得到:類「Doctrine_Record」未找到(從我的模型,其中它擴展Doctrine_Record) – jeremy 2012-04-04 19:21:54

+0

見我剛剛編輯 – AlienWebguy 2012-04-04 19:22:16

+0

企圖,相同的結果,找不到Doctrine_Record。問題已更新。 – jeremy 2012-04-04 19:31:01