Model extending CI_DB_active_record (Please Help Rick, Derek) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Model extending CI_DB_active_record (Please Help Rick, Derek) (/showthread.php?tid=1893) |
Model extending CI_DB_active_record (Please Help Rick, Derek) - El Forum - 07-03-2007 [eluser]Maurice Calhoun[/eluser] Active Record has a method $this->db->get(); Quote:Runs the selection query and returns the result. Can be used by itself to retrieve all records from a table But this does not make any sense to do this Here is my Conroller Code: class Blog extends Controller{ Here is my Model Code: class Post extends Model{ This seem redundant to me Is there a way to do just this my Controller Code: class Blog extends Controller{ Without have to recreate the same method that Active Record already has in the Model Model extending CI_DB_active_record (Please Help Rick, Derek) - El Forum - 07-03-2007 [eluser]rogierb[/eluser] You migth try something in your model like: Code: function getSomeTable($fields=null, $limit=null, $where=null) where $this->_table is defined in the contructor. Ow, I 'borrowed' the above code somewhere, so credit goes to... well, not me. Model extending CI_DB_active_record (Please Help Rick, Derek) - El Forum - 07-03-2007 [eluser]Maurice Calhoun[/eluser] Thanks, but thats not it? Sorry, What I want to do, is not to recreate Active Record methods. But extend the Model to them, so in my Controller I can do Code: $this->'model_name'->'active_record-method'() Code: $this->db->'active_record_method'() Code: function get(){ Model extending CI_DB_active_record (Please Help Rick, Derek) - El Forum - 07-31-2007 [eluser]gungbao[/eluser] most clean way to achieve it is to construct your derived objects against interfaces !!! or check the loader class, there is a nice code-statement: self:'bla' = $this, means you could try to link an alias pointer into the db-class functions self:get = &db;::activerecordmethod just an theoretical idea, try it yourself :-) and pls. let us know... Model extending CI_DB_active_record (Please Help Rick, Derek) - El Forum - 08-01-2007 [eluser]Maurice Calhoun[/eluser] gungbao, Thanks for the reply, but with the example I have above, how can I do what you have stated. What would be the syntax, and where would that syntax be placed? Model extending CI_DB_active_record (Please Help Rick, Derek) - El Forum - 08-01-2007 [eluser]Derek Allard[/eluser] You don't have to use a model. You could just call get directly in the controller, but if you want to use models, and you simply want to retrieve the whole table, exactly as db->get() does, then the way you've done it looks right to me. I'm moving this point into CI discussion where I think its a bit better suited. Model extending CI_DB_active_record (Please Help Rick, Derek) - El Forum - 08-01-2007 [eluser]Maurice Calhoun[/eluser] Derek, Yes, I know I can call db->get() from the controller, but I would like to keep the same name convention... If I have a Model name Post, and inside a method name "show_last_ten" the syntax would look like this ... Code: $this->post->show_last_ten(); Now the ActiveRecord has a method 'get', but in the controller the syntax is... Code: $this->db->get(); I would like to do (the same as ActiveRecord).... Code: $this->post->get(); but without having to re-create the 'get' method in my Model Do that make any sense? I just want to keep the same naming convention, this just looks funny to me in the controller... Code: $this->db->get(); |