找不到课程

时间:2012-04-04 19:13:16

标签: php doctrine-orm codeigniter-2 classnotfound

我是MVC和Codeigniter的新手,我正在尝试让一个班级工作。

我正在运行CodeIgniter 2.1.0和Doctrine 2.2.1

当我的代码调用submit()函数时,我得到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');
    }

在我的/ application / models /文件夹中,我有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 = '#*seCrEt!@-*%';
         $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 install / config有问题吗?

编辑:我遵循了这样调用类的建议:

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

我现在正在获取模型扩展的Class 'Doctrine_Record' not found Doctrine_Record

1 个答案:

答案 0 :(得分:0)

我怀疑您没有包含Myclass.php文件或路径不正确。如果您遇到Doctrine扩展程序的问题,则您的错误会提及父级。即使如此,请确保使用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');
    }