Should this function be in a helper, a controller, a model, or what? |
[eluser]w1ntermut3[/eluser]
Several pages on a site I'm building will require 'share this' functionality; the user will be provided with a copy'n'paste shareable URL, or a URL will be posted to their Facebook wall, etc etc ad nauseum. For this, we'd like to generate unique tracking codes to append to the shared URL. Part of generating the tracking code is logging it to the database. So, I've got to create a function that: a) Will need to load - or at least, have access to - a DB model b) Will be called by more than one controller And I don't know where to put it. Putting identical copies into each controller class seems stupid; from what I understand, putting stuff that needs to load a database model into a helper class is also bad practice. Where should this function go, in order to best fit the codeigniter MVC structure?
[eluser]w1ntermut3[/eluser]
Aha. That seems obvious now you say it I'd seen MY_controller mentioned but hadn't considered its use before. However, following the Wiki guide, I'm having some issues getting it to work. I'm getting an error: Quote:Fatal error: Class 'MY_Controller' not found in C:\dev\bit_campaign\application\controllers\home.php on line 3 I've created MY_Controller as: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); My Home controller starts: Code: class Home extends MY_Controller { What am I doing wrong? (Also - the wiki mentions that MY_Controller should extend Controller. However, my understanding was that, from CI 2.0, the core controller class is CI_Controller. Is this correct?)
[eluser]w1ntermut3[/eluser]
Ok, scratch that. The user guide docs seem more up to date. So MY_Controller should go into /application/core/, it should extent CI_Controller, and the constructor function should look like: Code: function __construct(){ That seems to work
[eluser]InsiteFX[/eluser]
The MY_Controller has to go into application/core not controllers! InsiteFX |
Welcome Guest, Not a member yet? Register Sign In |