• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My_Model don't auto Load by Core/Loader

#1
Hello,

I use Code Igniter 3.0.4 and I have a class MY_Model.php in repository application/core/ but when i call a model, the class MY_Model don't load.

With Code Igniter 3.0.0 this isn't not a bug !

I saw in the file /system/core/Loader.php at line 315 and there is the expression "require_once .... "  but not the expression new $class(); with in $class = "MY_Model"

I added to the line 320 and it goes !
Code:
$CI->$class = new $class();
My Class "My_Model"  is charged as soon as I call a model extends CI_Model

Can you take into account this modification for next release of Code Igniter 3 ?


Attached Files
.zip   Loader.zip (Size: 8.82 KB / Downloads: 61)
Reply

#2
No, it's not supposed to be instantiated. See this bug report: https://github.com/bcit-ci/CodeIgniter/issues/4350
Reply

#3
And to clarify further: MY_Model ("MY", not "My" - this is important) is getting loaded, contrary to your claim ... I suppose you mean something else.
Reply

#4
File : application/core/MY_Model.php


Code:
class MY_Model extends CI_Model
{

  // creer ici une propriete avec le nom de la database
  private $commun;

  public function __construct()
  {
    parent::__construct();
    log_message('debug', __CLASS__ . " Class Initialized");
   $this->commun = $this->load->database('commun', TRUE, TRUE);

    // Pass reference of database to the CI-instance
    $CI = & get_instance();
    // Creation d'une propriété dans la controlleur qui permet d'y acceder rapidement n'importe ou
    // $CI->my_data_base = & $this->my_data_base;
    $CI->commun = & $this->commun;
  }
}


On CI V3.0.0 I have the message "MY_Model Class Initialized" in the log.txt
On CI V3.0.4 I haven't this message, but with my code in system/core/Loader.php that's fine !

??

Thanks !
Reply

#5
You shouldn't need the MY_Model class to be instantiated in order for things to work properly. Whatever class extends MY_Model should simply call the parent::__construct() method in its constructor (if the constructor is defined) just as you have done in your MY_Model constructor.

Further, you shouldn't need to call get_instance() in MY_Model, since CI_Model defines a __get() method which does this for you. If you removed the definition of the $commun property from MY_Model, calling $this->commun = $this->load->database('commun', true, true); should do the same thing that you seem to be trying to do with the rest of the code in your constructor.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.