致命错误:找不到类“Modelmyaccount”

Posted

技术标签:

【中文标题】致命错误:找不到类“Modelmyaccount”【英文标题】:Fatal error: Class 'Modelmyaccount' not found 【发布时间】:2012-11-21 06:27:57 【问题描述】:

我正在使用 php 创建一个电子商务网站,并通过 XAMPP 加载。但是我遇到了以下错误:致命错误:找不到类'Modelmyaccount'

我曾尝试使用启用 XDebug 的 NetBeans 进行调试,但遇到了以下调用堆栈。

Call Stack

 1. main( ) ..\index.php:0
 2. require_once( 'E:\xampp\htdocs\promotion\system\codeigniter\CodeIgniter.php' ) ..\index.php:117
 3. myshop->__construct( ) ..\CodeIgniter.php:201
 4. CI_Loader->model( ???, ???, ??? ) ..\myshop.php:7

我已验证该类确实存在,但它似乎无法识别它。

下面以粗体突出显示的是它无法找到要存储到 $name 中的类名的部分

if ( ! class_exists('Model'))
    
        load_class('Model', FALSE);
    

    **require_once(APPPATH.'models/'.$path.$model.EXT);**

    $model = ucfirst($model);

    $CI->$name = new $model();
    $CI->$name->_assign_libraries();

    $this->_ci_models[] = $name;    

另请参阅下面的“modelmyaccount”和“Model”类以供参考:

<?
class modelmyaccount extends Model

    protected   $table_name = 'consumer_master';


    function __construct()
    
        parent::Model();

        $this->table_country_master     = 'country_master';
        //$this->table_country_detail   = 'country_detail';
        $this->table_state_master       = 'state_master';
        //$this->table_state_detail         = 'state_detail';
    

    function checkEmail()
    

      $fetch_user = "SELECT count(*) AS CNT FROM ".$this->table_name." 
                     WHERE email     = '".addslashes($_POST['email'])."'
                    ";
      $fetch_result=$this->db->query($fetch_user);      

      if($fetch_result->num_rows() > 0) 
           $row=$fetch_result->row_array();
           if($row['CNT'] == 0) 
              return true;
           else 
              return false;
          
      
   

   function updateMember($member_id)
   

    $dt = explode("-",addslashes($_POST['birth_date']));
    $birth_date = $dt[2]."-".$dt[0]."-".$dt[1];

    $saveSql = "UPDATE ".$this->table_name." 
                SET first_name      =   '".addslashes($_POST['first_name'])."',
                    last_name       =   '".addslashes($_POST['last_name'])."',
                    streetname          =   '".addslashes($_POST['address1'])."',   
                    dob     =   '".$birth_date."',
                    interest            =   '".addslashes($_POST['interest'])."',
                    country         =   '".addslashes($_POST['country'])."',
                    state           =   '".addslashes($_POST['state'])."',
                    city            =   '".addslashes($_POST['city'])."',
                    postal              =   '".addslashes($_POST['zip'])."',



                    edit_date   =   NOW()
                WHERE consumer_id = '".$member_id."'
                ";              
     //echo $saveSql;
     //exit;
      $saveResult = $this->db->query($saveSql);

      return true;  

   

   /*function delMyFav($member_id, $topic_type)
   
        $sql_del = "DELETE FROM favourite_master 
                    WHERE   member_id='".$member_id."' 
                    AND     topic_type='".$topic_type."'";
        $result = $this->db->query($sql_del);
   */

   function checkConfirmation($emailId)
   
     $sql = "SELECT status FROM ".$this->table_name." 
             WHERE   email ='".base64_decode($emailId)."'";
     $res = $this->db->query($sql);
     if($res->num_rows() > 0) 
       $row = $res->row_array();
       if($row['status']=='A') 
            return false;
       else 
            return true;
     
   

   function confirmMember($emailId)
   
     $confirmSql = "UPDATE ".$this->table_name. "
                    SET status = 'A' 
                    WHERE email ='".base64_decode($emailId)."'";

     $confirmResult = $this->db->query($confirmSql);

     if($confirmResult) 
       return true;
        
   

   function getCountry()
   
        $sql = " SELECT  CM.*
                 FROM  " .$this->table_country_master. " AS CM               
                 WHERE CM.is_active ='Y'";
        $recordSet = $this->db->query($sql);

        if($recordSet) 
            if($recordSet->num_rows() > 0) 
                foreach($recordSet->result_array() as $key =>$val) 
                    $rs[]=$val;
                
            
         else 
            return false;
        
        return $rs ;
   

   function getMemberById($member_id)
   

       $sql = "SELECT * FROM ".$this->table_name." WHERE consumer_id = '".$member_id."'";
       $recordset = $this->db->query($sql);

       if($recordset->num_rows() > 0)
           foreach($recordset->result_array() as $key=>$val)
               $rs[] = $val;
           
       else
            return false;   
       

       return $rs;
   

   function validateOldPassword($id)
       

        $this->old_pwd   = $this->input->request('old_pwd','');

        $sql = " SELECT count(*) AS CNT 
                 FROM   ".$this->table_name." 
                 WHERE  consumer_id ='".$id."' 
                 AND    password ='".$this->old_pwd."'
               ";       
        $rs  = $this->db->query($sql);

        if($rs) 
            if($rs->num_rows() > 0)  
                $row = $rs->row_array();
                if($row['CNT'] > 0) 
                  return true;
                 else 
                 return false;
                
             else 
                return false;
            
         else             
            return false;
        
    

    /*
    function valideNewPassword
    This function to check the New Password and Confirm New Password will be same or not
    if both are the same then return true else return false
    */
    function validateNewPassword() 
    
        $this->new_pwd        = $this->input->request('new_pwd','');
        $this->conf_new_pwd     = $this->input->request('con_pwd','');

        if($this->new_pwd!='' && $this->conf_new_pwd!='') 
            if($this->new_pwd===$this->conf_new_pwd) 
                return true;
             else 
                return false;
            
         else 
            return false;
        

    

    function updatePassword($id)
    
        $this->new_pwd   = $this->input->request('new_pwd','');


        $sql = " UPDATE ".$this->table_name." 
                 SET    password = '".$this->new_pwd."' 
                 WHERE  consumer_id ='".$id."'
               ";

        $rs  = $this->db->query($sql);

        if($rs) 
            return true;
         else             
            return false;
        
    

    function newsletterSubscription($subscriberEmail)
    
        $sql = "SELECT subscriber_email 
                FROM newsletter_subscriber
                WHERE subscriber_email = '".$subscriberEmail."'
                AND is_active = 'Y' 
                ";
        //echo $sql;
        $rs = $this->db->query($sql);
        if($rs)
            if($rs->num_rows() > 0)
                return true;
            else
                return false;
                   
        
    

    function subscribeNewsletter($subscriberEmail)
    
        $sql = "
                INSERT INTO newsletter_subscriber
                SET 
                    subscriber_email = '".$subscriberEmail."',
                    is_active = 'Y',
                    db_add_date = NOW(),
                    db_edit_date = NOW()            
               ";
        //echo $sql;       
        $rs = $this->db->query($sql);
        if($rs)
            return true;
        else
            return false;
        
       
    function unSubscribeNewsletter($subscriberEmail)
       
        $sql = "
                DELETE FROM newsletter_subscriber
                WHERE 
                    subscriber_email = '".$subscriberEmail."'               
               ";
        $rs = $this->db->query($sql);
        if($rs)
            return true;
        else
            return false;
                  

    


?>
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP 4.3.2 or newer
 *
 * @package     CodeIgniter
 * @author      ExpressionEngine Dev Team
 * @copyright   Copyright (c) 2008 - 2009, EllisLab, Inc.
 * @license     http://codeigniter.com/user_guide/license.html
 * @link        http://codeigniter.com
 * @since       Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * CodeIgniter Model Class
 *
 * @package     CodeIgniter
 * @subpackage  Libraries
 * @category    Libraries
 * @author      ExpressionEngine Dev Team
 * @link        http://codeigniter.com/user_guide/libraries/config.html
 */
class Model 

    var $_parent_name = '';

    /**
     * Constructor
     *
     * @access public
     */
    function Model()
    
        // If the magic __get() or __set() methods are used in a Model references can't be used.
        $this->_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE );

        // We don't want to assign the model object to itself when using the
        // assign_libraries function below so we'll grab the name of the model parent
        $this->_parent_name = ucfirst(get_class($this));

        log_message('debug', "Model Class Initialized");
    

    /**
     * Assign Libraries
     *
     * Creates local references to all currently instantiated objects
     * so that any syntax that can be legally used in a controller
     * can be used within models.  
     *
     * @access private
     */ 
    function _assign_libraries($use_reference = TRUE)
    
        $CI =& get_instance();              
        foreach (array_keys(get_object_vars($CI)) as $key)
        
            if ( ! isset($this->$key) AND $key != $this->_parent_name)
                       
                // In some cases using references can cause
                // problems so we'll conditionally use them
                if ($use_reference == TRUE)
                
                    $this->$key = NULL; // Needed to prevent reference errors with some configurations
                    $this->$key =& $CI->$key;
                
                else
                
                    $this->$key = $CI->$key;
                
            
               
    


// END Model Class

/* End of file Model.php */
/* Location: ./system/libraries/Model.php */

【问题讨论】:

如果您使用的是 Unix 系统,请注意名称大小写 我使用的是 Windows 7 系统。同一文件夹中的其他类能够通过。但是某些课程不会这样做。这是“ModelMyAccount”的类之一,但是我已将其更改为“modelmyaccount”。但仍然没有工作。有没有我可能错过的地方? 你是说其他模型加载正常吗?你检查错别字了吗? 1.你是如何实例化类和 2。你的类在实例化中是如何拼写的,即。类 ModelMyAccount .....? 我用记事本++打开了所有的.php文件,找到'ModelMyAccount'并用'modelmyaccount'替换它。存储在我的应用程序目录中的 .php 文件也具有名称 modelmyaccount.php 【参考方案1】:

这可能会有所帮助: CodeIgniter User Guide - Models

如果您查看“模型剖析”,您会发现您需要更正 CodeIgniter 的命名约定才能正确找到您的模型。你的类名必须首字母大写,如下所示:

class Modelmyaccount extends Model 

此外,如果您想正确遵循 CodeIgniter 命名约定;你应该将你的文件命名为my_account_model.php。另外,相应地更改类名,如下所示:

class My_account_model extends Model

此外,您使用的是哪个版本的 CodeIgniter?你的模型应该扩展CI_Model,或者如果你使用你自己的模型类扩展,它应该是MY_Model,除非你在config.php文件中设置不同的前缀。

因此,如果您使用的是 2.1.3 版本,您的模型类声明应如下所示:

class My_account_model extends CI_Model 

CI_ 替换为您使用的前缀。

【讨论】:

以上是关于致命错误:找不到类“Modelmyaccount”的主要内容,如果未能解决你的问题,请参考以下文章

Laravel - 致命错误:未捕获的错误:找不到类'Auth'

致命错误:未捕获的错误:找不到类“App\Config”

“PHP 致命错误:找不到类 'HttpRequest'”

为啥致命错误:未捕获的错误:找不到类“Illuminate\Foundation\Application”

PHP致命错误:找不到类

PHP致命错误:未捕获错误:找不到类