is loading through static class is bad idea? |
hi
i use following class to load the views like Load::view("welcome.php"); is it bad idea? or its fine? i am not sure for using lots of instances? <?php Class Load{ static function view($view, $data = null){ $obj =& get_instance(); return $obj->load->view($view, $data); } static function model($model){ $obj =& get_instance(); return $obj->load->model($model); } static function library($lib, $config = null, $obj_name = null){ $obj =& get_instance(); return $obj->load->library($lib, $config, $obj_name); } static function helper($helper){ $obj =& get_instance(); return $obj->load->helper($helper); } ?> thank
What's the reason you want to do this?
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
PHP Code: function ohce( $str ){ (06-12-2017, 01:01 PM)albertleao Wrote: What's the reason you want to do this? two reasons 1. static classes are more editor friendly. For example its hard to autocomplete on editor when we have codeigniter. but static works nicely. 2. its more good looking : and less codes to write. $this->load->view("welcome.php"); vs Load::view("welcome.php"); If we have a real big project we can save lots time. Now the question is WHY NOT?
Less code is not necessarily the best code (unless you are playing code golf).
Great code is beautiful because it is easily followed, clear, DRY, easily maintained, well thought out, robust and flexible. (06-13-2017, 07:15 AM)kharota Wrote: I understand but why not use less code? if we have big project? Are not they doing same thing in laravel? Please have a look at laravel facades. It sounds like you have your reasons. I've used Laravel a few times, but I prefer CodeIgniter. I've been guilty of doing things my way for as long as I've been coding, and don't see any reason why you shouldn't do things your way. If you like facades, then go for it .... but at least do it a little cleaner. How about this: PHP Code: <?php
(06-13-2017, 11:20 AM)PaulD Wrote: Less code is not necessarily the best code (unless you are playing code golf). Sir, if less code is same code why not use that one? $this->load->view (has 17 chars) Load::view (has 10 chars) how many more hours i have to do (for simple thing) if i have to go through all loading and other stuff? time is money and as freelancer its even more costly. I understand your point. are not we using frameworks to save our time? (06-13-2017, 11:38 AM)skunkbad Wrote:(06-13-2017, 07:15 AM)kharota Wrote: I understand but why not use less code? if we have big project? Are not they doing same thing in laravel? Please have a look at laravel facades. Thank you, Its perfect code. I am asking little different thing and that is =& get_instance() doesnt create new instance all the time. Therefore it should not slower the framework right? Second thing is still autocomplete doesnt work in editors because editor dont compile the codes instead they use created functions in class. Any solution for that? I have edited my code with your codes PHP Code: class Load Your comments please |
Welcome Guest, Not a member yet? Register Sign In |