Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter 3.1.6: Unable to locate the model you have specified
#1

(This post was last modified: 10-31-2017, 10:46 PM by DorkSQLi.)

Sorry for bad English.
I have 1 model file from the composer, previously I used CI version 3.0.x  with the following configuration it's working.  Big Grin

config.php
PHP Code:
$config['composer_autoload'] = FCPATH 'vendor/autoload.php'

autoload.php
PHP Code:
$autoload['model'] = array('Crud'); 

My Model location in `ROOTPROJECT/vendor/package/my-package/models/Crud.php'
PHP Code:
<?php
defined
('BASEPATH') or exit('No direct script access allowed');

class 
Crud extends CI_Model {

    public function 
__construct() { parent::__construct(); }

    public function 
createData($table$data) {
        
$this->db->insert($table$data);
        return 
$this->db->error();
    }



From the composer side has also been made autoload Crud.php
Code:
{
"autoload": { "classmap": ["models/Crud.php"] }
}

When I update the CI system to version 3.1.6 by following all previous changes, it is not working. Huh
Code:
An uncaught Exception was encountered
Type: RuntimeException
Message: Unable to locate the model you have specified: Crud
Filename: /media/LocalDiskD/DorkSQLi/htdocs/CodeIgniter/system/core/Loader.php
Line Number: 344

I am trying to change the file system / core / Loader.php line 324, the result nothing error.
PHP Code:
if ( ! class_exists($modelFALSE)) { ... }

if ( ! class_exists($modelTRUE)) { ... } 


CodeIgniter 3.1.6 system/core/Loader.php line 323-350
PHP Code:
$model ucfirst($model);
        if ( ! 
class_exists($modelFALSE))
        {
            foreach (
$this->_ci_model_paths as $mod_path)
            {
                if ( ! 
file_exists($mod_path.'models/'.$path.$model.'.php'))
                {
                    continue;
                }

                require_once(
$mod_path.'models/'.$path.$model.'.php');
                if ( ! 
class_exists($modelFALSE))
                {
                    throw new 
RuntimeException($mod_path."models/".$path.$model.".php exists, but doesn't declare class ".$model);
                }

                break;
            }

            if ( ! 
class_exists($modelFALSE))
            {
                throw new 
RuntimeException('Unable to locate the model you have specified: '.$model);
            }
        }
        elseif ( ! 
is_subclass_of($model'CI_Model'))
        {
            throw new 
RuntimeException("Class ".$model." already exists and doesn't extend CI_Model");
        } 

CodeIgniter 3.0.1 system/core/Loader.php line 293-320
PHP Code:
$model ucfirst(strtolower($model));
        if ( ! 
class_exists($model))
        {
            foreach (
$this->_ci_model_paths as $mod_path)
            {
                if ( ! 
file_exists($mod_path.'models/'.$path.$model.'.php'))
                {
                    continue;
                }

                require_once(
$mod_path.'models/'.$path.$model.'.php');
                if ( ! 
class_exists($modelFALSE))
                {
                    throw new 
RuntimeException($mod_path."models/".$path.$model.".php exists, but doesn't declare class ".$model);
                }

                break;
            }

            if ( ! 
class_exists($modelFALSE))
            {
                throw new 
RuntimeException('Unable to locate the model you have specified: '.$model);
            }
        }
        elseif ( ! 
is_subclass_of($model'CI_Model'))
        {
            throw new 
RuntimeException("Class ".$model." already exists and doesn't extend CI_Model");
        } 


how to avoid the error without having to change the file system CodeIgniter? Huh
Reply
#2

Models are meant for application-specific, business logic. That's simply not something you put into a composer package.
Reply
#3

(11-01-2017, 04:24 AM)Narf Wrote: Models are meant for application-specific, business logic. That's simply not something you put into a composer package.

Thanks for informing Me.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB