找不到课程 [英] Class not found

查看:61
本文介绍了找不到课程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MVC和Codeigniter的新手,正在尝试让一堂课上课.

I'm new to MVC and Codeigniter and am trying to get a class working.

我正在运行CodeIgniter 2.1.0和Doctrine 2.2.1

I'm running CodeIgniter 2.1.0 and Doctrine 2.2.1

当我的代码调用Submit()函数时,我得到 Class'Myclass_model'not found ,并引用了包含以下内容的行: $ u = new Myclass_model();

When my code calls the submit() function, I get Class 'Myclass_model' not found, and references to the line that includes: $u = new Myclass_model();

(请参见底部的编辑说明,现在在扩展模型中未找到 Class'Doctrine_Record')

(See edit note at the bottom, now getting Class 'Doctrine_Record' not found in the model where it is extended)

在我的控制器中是以下代码:

In my controller is the following code:

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:

And in my /application/models/ folder I have 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可用,已配置等.

I suspect that my problem is with extending Doctrine_Record. I have doctrine2 installed, and in /application/libraries/ I have Doctrine.php and the Doctrine folder. But I'm not sure where to check, or even how to check and make sure that Doctrine_Record is available, configured, etc.

有人可以帮我解决这个问题,找出问题所在吗?我班上的事情简单吗?我的Doctrine安装/配置有问题吗?

Can anyone help me troubleshoot this and figure out where the problem lies? Something simple with my class? Some problem with my Doctrine install/config?

我遵循这样的建议:

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

现在在模型扩展了Doctrine_Record的地方得到了 Class'Doctrine_Record'

推荐答案

我怀疑您没有包含您的 Myclass.php 文件或路径不正确.如果您在使用Doctrine扩展程序时遇到问题,则您的错误将提及父级.甚至还要确保将父文件包含在新类中,并带有 include_once('path/to/doctrine_record');

I suspect you didn't include your Myclass.php file or have an incorrect path. If you were having issues with the Doctrine extension, your error would mention the parent. Even still, make sure you include the parent file inside your new class with a include_once('path/to/doctrine_record');

您可以将其添加到 autoload.php 文件中,或手动添加:

You can add it to the autoload.php file or manually like so :

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 :)

Or even better, you load it like a model. Rename the file to myclass_model.php and the class name to 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');
    }

这篇关于找不到课程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆