![]() |
Help with helpers - 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: Help with helpers (/showthread.php?tid=33556) Pages:
1
2
|
Help with helpers - El Forum - 08-31-2010 [eluser]gmask[/eluser] Alright so I have this simple db query: Code: // Get global settings Help with helpers - El Forum - 08-31-2010 [eluser]Met[/eluser] you can extend the default controller and place it in there, or as you say, you can put it in a helper. Set the helper to autoload, then simply Code: //if not autoloading ~ Help with helpers - El Forum - 08-31-2010 [eluser]gmask[/eluser] Hi Met, I tried what you suggested, but something's gone wrong. My helper: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed.'); Code: function index() Quote:A PHP Error was encountered Help with helpers - El Forum - 08-31-2010 [eluser]gyo[/eluser] Generally helpers are not Classes, they are just procedural functions to be used everywhere. Code: $this->load->helper('my_helper'); Help with helpers - El Forum - 08-31-2010 [eluser]gmask[/eluser] Right, that's why I thought making a helper with this function would be the best way to do this. Could you suggest a better way? Or is there something I should change about the helper I have now? Thanks very much for your help. Help with helpers - El Forum - 08-31-2010 [eluser]Met[/eluser] sorry my example probably confused you. posted it as $this->my_helper->my_function out of habit more than anything. yes, helpers are just functions rather than a class, so as gyo / suashi posted, should do the trick nicely. Help with helpers - El Forum - 08-31-2010 [eluser]gmask[/eluser] Thanks a ton, guys! Help with helpers - El Forum - 08-31-2010 [eluser]gyo[/eluser] As I see it, settings() should be in a model. Helpers are more intended to be used in views (or if you need a simpler approach rather than object oriented). Help with helpers - El Forum - 08-31-2010 [eluser]InsiteFX[/eluser] What's wrong with using a MY_Controller? InsiteFX Help with helpers - El Forum - 08-31-2010 [eluser]gmask[/eluser] [quote author="InsiteFX" date="1283288569"]What's wrong with using a MY_Controller?[/quote] I don't understand. Quote:As I see it, settings() should be in a model.Ok I see what you mean. I made the following changes: my helper: Code: function settings() Code: <?php $setting = settings(); ?> Is there a way to do this better? Or at least a way to make the variables prettier? I'd like to be able to just call one variable for each, instead of the array thing. Like $site_title for the site title, etc. |