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

#34
(12-31-2014, 12:19 PM)includebeer Wrote: I know what it does. I just don't understand your concern. If you're afraid to use this class, then don't. CI doesn't force you to use anything. But I don't see any good reason not to. Can you give an example where it would cause problems?
I don't expect I will use CI_Model, mostly because it might get confusing if I wanted to give my own model class a property with any of these names:
Code:
benchmark
hooks
config
log
utf8
uri
router
output
security
input
lang
load
session
db
All of these properties are defined by the CodeIgniter object and if you define a trivial class with no properties that extends CI_Model, it looks like that trivial object has all of those properties. I can see how this might be handy, but This just seems weird to me:
Code:
class Test_model extends CI_Model {
    public function __construct() {
        var_dump($this->lang); // yields object(CI_Lang)#11 (2) { ["language"]=> array(0) { } ["is_loaded"]=> array(0) { } }
    }
}
I can see how it might be convenient to have access to the entire CI environment within one's models, but I believe it reduces the modularity of one's code to depend on this elaborate object automatically being instantiated whenever I need a model. If I did actually want such a complex object attached automatically to every model I create, I would defintely want it at least to have its own property within my model class (e.g., $this->ci->lang) instead of automagically inserting its own 14 properties into every model I have.

I have also noticed that creating a class that extends CI_Model like this:
PHP Code:
class Test_model extends CI_Model {
    public function 
__construct() {
        die(
"Here i am!");
    }

will mean you have to include/require system/core/Model.php or you get this error:
Code:
Fatal error: Class 'CI_Model' not found in /var/www/erep-v4/application/models/Test_model.php on line 2
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-31-2014, 01:13 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.