1

我正在使用 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 */
4

1 回答 1

0

这可能会有所帮助: CodeIgniter 用户指南 - 模型

如果您查看“模型剖析”,您会发现您需要更正您的命名约定,以便 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_为您使用的前缀。

于 2012-12-08T20:47:06.340 回答