• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Where to put plain object classes?

#25
I could extend CI_Model, I suppose, but why would I do this? The class doesn't look especially feature-rich. All it does is write a log message when constructed and then define a __get magic method that refers to the CodeIgniter singleton. I could be completely missing something, but I wonder why I would want to have my DataObjects coughing up properties of the CI singleton object as if those properties were its own? What happens when my DataObject defines a property that already belongs to the CI singleton?
Code:
class CI_Model {

    /**
     * Class constructor
     *
     * @return    void
     */
    public function __construct()
    {
        log_message('debug', 'Model Class Initialized');
    }

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

    /**
     * __get magic
     *
     * Allows models to access CI's loaded classes using the same
     * syntax as controllers.
     *
     * @param    string    $key
     */
    public function __get($key)
    {
        // Debugging note:
        //    If you're here because you're getting an error message
        //    saying 'Undefined Property: system/core/Model.php', it's
        //    most likely a typo in your model code.
        return get_instance()->$key;
    }

}
Reply


Messages In This Thread
Where to put plain object classes? - by geekita - 12-02-2014, 05:51 AM
RE: Where to put plain object classes? - by sneakyimp - 12-28-2014, 08:40 PM
RE: Where to put plain object classes? - by Jamie - 01-06-2015, 05:18 AM
RE: Where to put plain object classes? - by Jamie - 01-06-2015, 03:08 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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