What to do??? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: What to do??? (/showthread.php?tid=28565) |
What to do??? - El Forum - 03-15-2010 [eluser]sudinem[/eluser] I have created a dynamic drop down menu which I need to show it through out whole site. But, the problem is that I need to copy paste the code in each an every functions of the controller. How can I reuse the code???? What to do ?? Plz help !!!! Sudinem What to do??? - El Forum - 03-15-2010 [eluser]danmontgomery[/eluser] http://ellislab.com/codeigniter/user-guide/general/helpers.html What to do??? - El Forum - 03-15-2010 [eluser]sudinem[/eluser] I'm not asking about how to create a dropdown menu. I'm asking instead of pasting the same code several times how can I manage to put it as the form of global variable. I've tried to create a library but inside library I can't load the model so as to generate the result from database. Sudinem What to do??? - El Forum - 03-15-2010 [eluser]bretticus[/eluser] [quote author="sudinem" date="1268733025"]I'm not asking about how to create a dropdown menu.[/quote] Not sure how you thought the suggestion of using a helper was explaining how to build a dropdown function... However... A helper is a standard way of reusing code that performs a repetitive task (because an helper is just a collection of related functions.) Your example, however, is a perfect candidate for a model (especially since you are using the database class.) What to do??? - El Forum - 03-15-2010 [eluser]sudinem[/eluser] thanx bretticus 4 ur reply I'm gonna try it and reply if sth goes wrong. Sudinem What to do??? - El Forum - 03-16-2010 [eluser]sudinem[/eluser] How to call model's function inside the helper function??? Is it possible to call?? What to do??? - El Forum - 03-16-2010 [eluser]bretticus[/eluser] [quote author="sudinem" date="1268779382"]How to call model's function inside the helper function???[/quote] Why do you need to call it from a helper function? Why not call it directly? the answer is, of course, to get an instance of the CI super object. Code: function some_helper_func() What to do??? - El Forum - 03-16-2010 [eluser]sudinem[/eluser] A PHP Error was encountered Severity: Notice Message: Undefined property: Maker_Model::$db Filename: models/maker_model.php Line Number: 13 Fatal error: Call to a member function count_all() on a non-object in C:\Program Files\xampp\htdocs\CodeIgniter\system\application\models\maker_model.php on line 13 I got this error following ur instruction What to do??? - El Forum - 03-16-2010 [eluser]bretticus[/eluser] [quote author="sudinem" date="1268783156"] I got this error following ur instruction[/quote] I haven't actually given you any instructions. I have never seen your code. Thus, I have done nothing more that make suggestions. That being said... This notice (not an error) is generated from what seems to be you trying to access db as a property of your model. Yes, since models extend the Model class, you can access the db object via $this->db INSIDE your model class. You cannot access via: Code: $this->your_model->db->count_all() Which I can only guess at because you haven't actually posted any code. |